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: How to: index data from a for loop
Replies: 2   Last Post: Apr 4, 2014 10:00 AM

 Messages: [ Previous | Next ]
 Curious Posts: 2,359 Registered: 12/6/04
Re: How to: index data from a for loop
Posted: Apr 4, 2014 10:00 AM

"Nasser M. Abbasi" wrote in message <lhl6gq\$bve\$1@speranza.aioe.org>...
> On 4/3/2014 8:50 PM, Max wrote:
> > Hi, I'm trying to figure out how to store a set of data from within a 'for' loop.
>
> N = 10;
> A = zeros(N,2); %make space for storage
>
> for i=1:10
> mu = rand();
> pf = rand();
> A(i,:) = [mu,pf]; % STORE THEM
> end
> A
>
> title(A(1,:)); % my title ?
>
>

% Or use cell arrays by changing:

A(i,:) = [mu,pf]; % STORE THEM

% to:

A{i} = [mu,pf]; % STORE THEM - Note the curley brackets

% You can mix scalars, vectors, matricies, & characters in a cell array.

% See:

<<http://www.mathworks.com/help/matlab/cell-arrays.html>>