COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Saving data in for loop

• Follow

```I am running a function in a for loop where the input data are from a 3D matrix with dimensions 10 x 4  x 223 (dataazi). The outputs from the function are an n x 4 matrix (dat_out) and an m x 1 vector (b). The issue is I am unable to save the results from each iteration because some iterations of data_out and b presumably have empty arrays. How could I save all the data from each iteration without overwriting the data?

nRC=size(dataazi);

nCol= nRC(3);
for m=1:nCol;
[dat_out,b]=rfb_ld(dataazi(:,:,m),1,1);

Rem_dat(:,m)=b; %Put the result in a vector called Rem_dat
end
```
 0

```On 26/01/11 12:06 AM, Alex wrote:
> I am running a function in a for loop where the input data are from a 3D
> matrix with dimensions 10 x 4 x 223 (dataazi). The outputs from the
> function are an n x 4 matrix (dat_out) and an m x 1 vector (b). The
> issue is I am unable to save the results from each iteration because
> some iterations of data_out and b presumably have empty arrays. How
> could I save all the data from each iteration without overwriting the data?
>
> nRC=size(dataazi);
> nCol= nRC(3); for m=1:nCol; [dat_out,b]=rfb_ld(dataazi(:,:,m),1,1);
> Rem_dat(:,m)=b; %Put the result in a vector called Rem_dat
> end

You could use a cell array:

Rem_dat{m} = b;

```
 0

```Bingo!!
Thanks Think blue, count two!
```
 0

2 Replies
565 Views

Similiar Articles:

7/20/2012 5:23:24 AM