Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: Saving matrix each iteration
Posted: Sep 19, 2013 10:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"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
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.