Help with Multiple Loops

2 ビュー (過去 30 日間)
Carolyn
Carolyn 2013 年 8 月 5 日
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.

採用された回答

mano49j
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
  1 件のコメント
Carolyn
Carolyn 2013 年 8 月 7 日
This worked beautifully, thanks.

サインインしてコメントする。

その他の回答 (2 件)

Iain
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

Andrei Bobrov
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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by