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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!