Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Saving matrix each iteration
Replies: 5   Last Post: Sep 20, 2013 10:35 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,038 Registered: 12/7/04
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 %d-by-%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 1-by-1 because 51 is 1-by-1. Again, I recommend just using
them as stored in the cell array.

--
Steve Lord
slord@mathworks.com
http://www.mathworks.com

Date Subject Author
9/18/13 John Dickson
9/18/13 Steven Lord
9/19/13 John Dickson
9/19/13 Steven Lord
9/20/13 John Dickson
9/20/13 Steven Lord