Help with Multiple Loops

2 vues (au cours des 30 derniers jours)
Carolyn
Carolyn le 5 Août 2013
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.

Réponse acceptée

mano49j
mano49j le 7 Août 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
  1 commentaire
Carolyn
Carolyn le 7 Août 2013
This worked beautifully, thanks.

Connectez-vous pour commenter.

Plus de réponses (2)

Iain
Iain le 5 Août 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

Andrei Bobrov
Andrei Bobrov le 7 Août 2013
Modifié(e) : Andrei Bobrov le 7 Août 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

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by