0
votes

I have a text file that contains 2 columns and n number of rows separated by tab as delimiter.

Example file.txt:

180     -8.3
111    -98.3
111.3    11.22
121      44

I want to load the above into MATLAB and have an n-by-2 array as follows:

array[0,0]=180
array[0,1]=-8.3
array[1,1]=111

...and so on. How can I do that?

2

2 Answers

0
votes

Check the documentation for load function.

myArray = load('myFile.txt', '-ascii'); % return matrix

By the way, matlab index starts at 1.

0
votes

It's as simple as:

array = importdata('file.txt');

If it must be an array and not a matrix, check out the matlab function mat2cell here