loading a 2d matrix from a text file comes in as an array

I have two columns of data in a text file that I'm trying to read in using the load function. For some reason it is loading the file as a single array (1 x 1340) instead of a matrix (670 x 2). I am using the 2012a and I'm on a Mac.

1 Comment

Just figured out that it doesn't like the format the data was saved in. I opened it in excel, then saved it as a windows text file, and it worked. Tab delimited did not work. Any thoughts on how to make it work without resaving all of my text files as windows text files?

Sign in to comment.

Answers (1)

If its loading as a single array, depending on the order of your data you can For example:
x y
1 10
2 20
3 30
If the data comes like
data=[1 2 3 10 20 30]
n=numel(data)
x=data(1:n/2)
y=data(n/2+1:end)
If data comes like
data=[1 10 2 20 3 30];
x=data(1:2:end);
y=data(2:2:end)

Asked:

on 22 Feb 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!