From: Shafi on
I am a new matlab user and facing a problem while using a for loop. I'll appreciate if anybody help me in this regard.

My loop if like below:

for i=1:100
[P]=getdata(i);

end
[P] is i depended and 'getdata' will produce a 40x 40 matrix for each value of i.

I want catch all 100, 40x 40 matrix and want to use them in later calculation.

Is there anyone who can hep me in this case.
Regards
Shafi
From: Walter Roberson on
Shafi wrote:
> I am a new matlab user and facing a problem while using a for loop. I'll
> appreciate if anybody help me in this regard.
>
> My loop if like below:
>
> for i=1:100
> [P]=getdata(i);
>
> end
> [P] is i depended and 'getdata' will produce a 40x 40 matrix for each
> value of i.
> I want catch all 100, 40x 40 matrix and want to use them in later
> calculation.
>
> Is there anyone who can hep me in this case.

P = cell(100,1);
for i = 1:100
P{i} = getdata(i);
end

Alternately,

P = zeros(40,40,100);
for i = 1:100
P(:,:,i) = getdata(i);
end

The second form can be used only for numeric arrays that are all the
same size, but is faster. The first form can be used even if getdata()
returns different sizes and types of values for the different i.
From: Shafi on
Thanks a lot. Your solution was helpful.
Regards
Shafi

"Shafi " <aitmsi(a)yahoo.com> wrote in message <hsmjqu$md5$1(a)fred.mathworks.com>...
> I am a new matlab user and facing a problem while using a for loop. I'll appreciate if anybody help me in this regard.
>
> My loop if like below:
>
> for i=1:100
> [P]=getdata(i);
>
> end
> [P] is i depended and 'getdata' will produce a 40x 40 matrix for each value of i.
>
> I want catch all 100, 40x 40 matrix and want to use them in later calculation.
>
> Is there anyone who can hep me in this case.
> Regards
> Shafi