Save data from a loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!