Save data from a loop

3 vues (au cours des 30 derniers jours)
Joshua
Joshua le 3 Juil 2012
Hello,
This may be simple to figure out but for some reason I can't seem to get the answer I want.
for f=1:40;
for g=1:40;
for i=1:1:1600;
dpTxcouple1(:,:,i)=Txcouple(33,g,f)*B(:,:,1);
end
end
end
What I would like to do is save each result when multiplying the element in the 33rd row of each column and page of matrix Txcouple (41x40x40) by the first page of matrix B (41x17x24). This should provide me with a matrix that is 41x17x1600 since page 1 of matrix B should be multiplied 40x40 times at the 33rd row of matrix Txcouple. When I try the code above the last result is repeated in all 1600 pages. I'm not sure what I am doing wrong but any help would be greatly appreciated!
Thank you!

Réponses (1)

Geoff
Geoff le 4 Juil 2012
I think this might be what you want:
for f = 1:40
for g = 1:40
i = (f-1) * 40 + g;
dpTxcouple1(:,:,i) = Txcouple(33,g,f) * B(:,:,1);
end
end
  1 commentaire
Walter Roberson
Walter Roberson le 4 Juil 2012
Another way of writing that would be
for f = 1:40
for g = 1:40
dpTxcouple1(:,:,f,g) = Txcouple(33,g,f) * B(:,:,1);
end
end
dpTxcouple1 = reshape( dpTxcouple1, size(dpTxcouple1,1), size(dpTxcouple1,2), 40*40 );

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by