The Math Forum

Search All of the Math Forum:

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

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

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

Advanced Search

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

Posts: 18,038
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" <> wrote in message
> 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);
for k = 10:-1:1
x = C{k};
fprintf('C{%d} is %d-by-%d\n', k, size(x, 1), size(x, 2));

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

> 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
To contact Technical Support use the Contact Us link on

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.