MATLAB Answers

0

Save data from a loop

Joshua 님이 질문을 제출함. 3 Jul 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!

  댓글 수: 0

로그인 to comment.

답변 수: 1

Geoff 님의 답변 4 Jul 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

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 );

로그인 to comment.



Translated by