MATLAB Answers

Save data from a loop

1 view (last 30 days)
Joshua
Joshua on 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 Comments

Sign in to comment.

Answers (1)

Geoff
Geoff on 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 Comment

Walter Roberson
Walter Roberson on 4 Jul 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 );

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!