Reading data from a larger matrix into individual variables

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

It would be much easier if we had your ‘MagData.xlsx’ file or a representative section of it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Daniel LaCroix
Daniel LaCroix 2015년 12월 11일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2015년 12월 10일

편집:

2015년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by