loading a 2d matrix from a text file comes in as an array
Show older comments
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.
Answers (1)
Azzi Abdelmalek
on 22 Feb 2013
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)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!