Reading data from a larger matrix into individual variables
5 views (last 30 days)
Show older comments
Howdy all,
I have data from 12 different lines of a survey that I am trying to separate. Everyting is grouped together in one matrix and instead of going through and looking for the index where one set stops and the next begins I wanted to create a for loop that reads data for one line into a variable and then repeats for each line. I am able to get 12 different arrays but instead of reading just one line, it reads the entire data set so now I have 12 different variables with all the same values.My code right now is:
filename = 'MagData.xlsx';
M = xlsread(filename);
j = M(:,8);
for i = [1:12]
for j = i
T{i} = M(:,3);
B{i} = M(:,4);
x{i} = M(:,2);
end
end
Any help would be appreciated
Edit
So I realize I didn't do a very good job explaining the problem. The matrix is 7940x9 where each row is one measurement from the survey. Each survey line has a couple hundred measurements but they are all different lengths so for example survey line 12 is (1:265,:) and line 11 is (266:492,:). I am trying to assign values from columns 2,3,and 4 into separate variables. Column 8 shows which line you are looking at so (1:265,8) is just an array of 12 while (266:492,8) is an array of 11. I hope this helps.
1 Comment
Star Strider
on 11 Dec 2015
It would be much easier if we had your ‘MagData.xlsx’ file or a representative section of it.
Answers (1)
Daniel LaCroix
on 11 Dec 2015
If I understand your question correctly, there's no need for loops. My understanding is that you want to make a matrix with 12 rows into 12 separate variables.
To make the first row its own variable, type M(1,:). The colon tells MATLAB you want all the columns of the first row. You will have to make 12 lines to do this, because the variable name will change each time so a loop won't work, but making 12 lines isn't too tedious. (Maybe there is a way, but you'll have to ask somebody more experienced than me.)
I hope this helps.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!