Help with Multiple Loops
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
mano49j
2013-8-7
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
更多回答(2 个)
Iain
2013-8-5
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 个评论
Andrei Bobrov
2013-8-7
编辑:Andrei Bobrov
2013-8-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!