Help with Multiple Loops
2 views (last 30 days)
Show older comments
I'm fairly new to Matlab and am trying to learn how to write loops for a project at work. I imported data from Excel using xlsread. I have a column of data that is 13689 points long. I need to input this data into a matrix 117 x 177 beginning at row 117 and column 1. Then fill in all the columns before starting on the next row, 116. So far this is what I have,
IntWL = xlsread('C:\***')
L = length(IntWL);
C = zeros(117,117);
format('short','g')
for h = n:-1:1
for j = 1:L
for i = j:117
x(i) = IntWL(j);
C(h,i) = x(i);
end
end
end
This puts the first 117 data points into row 117, columns 1 - 117 of the C matrix. What I can't seem to figure out is when it finishes the first iteration, how do I get it to go to the 118th data point (of my original data) and count the next 117 data points and insert them into row 116 of my matrix C. What I end up with is the same 117 data points in all my rows. Any help would be greatly appreciated. Carolyn
lain, thanks for responding to my earlier post. I realized that I need to approach my problem from a different perspective.
0 Comments
Accepted Answer
mano49j
on 7 Aug 2013
k = 0; for i = 117:-1:1
for j = 1:117
k = k+1;
C(i,j) = intWL(k,1)
end
end
i - indicates row number,
j - indicates column number..,,
-----enjoy
More Answers (2)
Iain
on 5 Aug 2013
I'm not entirely clear on what you're trying to do, but, I reckon you're after:
MWL = reshape(MxWtLvl,117,[])';
MWL = flipud(MWL);
or:
for i = 1:117
for j = 1:117
MWL(118-j,i) = MxWtLvl((i-1)*117 + j);
end
end
0 Comments
Andrei Bobrov
on 7 Aug 2013
Edited: Andrei Bobrov
on 7 Aug 2013
C = rot90(reshape(IntWL,117,[]));
or
n = numel(IntWL);
k = 117;
C = IntWL(bsxfun(@minus,n-k+1:n,(0:k:n-k)'));
or
n = numel(IntWL);
k = 117;
for jj = 1:k
C(k-jj+1,:) = IntWL((jj-1)*k+1:k*jj);
end
0 Comments
See Also
Categories
Find more on Data Distribution Plots 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!