
Re: Saving matrix each iteration
Posted:
Sep 19, 2013 10:29 AM


"Sincloe Brans" <dickson.f1@gmail.com> wrote in message news:l1e233$8io$1@newscl01ah.mathworks.com... > So I get a cell B{j} in which B{1}=150*85, B{51} = 160*85 B{101} =170*85, > how do I convert them to separate matrices?
Why? Just refer to them as B{1}, B{51}, B{101}, etc.
If you need to iterate through them to do something and don't want to write B{1} all the time, you can create a temporary matrix that contains the contents of the matrix you're currently processing:
C = cell(1, 10); for k = 1:10 C{k} = magic(k); end for k = 10:1:1 x = C{k}; fprintf('C{%d} is %dby%d\n', k, size(x, 1), size(x, 2)); end
If you want to create B1, B2, ... B51, ... B101 DON'T DO THIS. See question 1 in the Programming section of the FAQ for an explanation why this is a Bad Idea.
http://matlab.wikia.com/wiki/FAQ
> When I do cell2mat it converts the whole thing in the cell to ONE matrix, > but I need to create separate matrices, any idea how to? > so that new c(i) =150*85, c(51) =160*85 henceforth.
You can't, at least not without creating your own object. If c is a matrix, c(51) will be 1by1 because 51 is 1by1. Again, I recommend just using them as stored in the cell array.
 Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com

