Save data from a loop

조회 수: 2 (최근 30일)
Joshua
Joshua 2012년 7월 3일
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!

답변 (1개)

Geoff
Geoff 2012년 7월 4일
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
Walter Roberson
Walter Roberson 2012년 7월 4일
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 );

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by