From: Patrick on
Hello,

I want to use the eval command to concatenate vectors which are created with a loop.
Here is the code:

for a=79:79 %year
for b=1:12 %month
[Mod_precip_hourly]=RealTS_fu('Z:\','MMSFC_dewAc.',a,b,a,b,1,63,2)
eval(sprintf('m%d = [Mod_precip_hourly]', b));

end
end

This creates 12 vectors of dim 744x1 (Jan), 672x1 (Feb), 744x1 (Mar) ... (depending on the month) which are assigned to the variables m1,...,m12.

Finally, I could simply concatenate using e.g. m1979=cat(2,m1,,2,..,m12), however, I would prefer a more generic solution, e.g. depending on the numer of the available months, maybe with cat in combination with the the eval command in the inner loop? I have no idea how this will work.

I would appreciate any suggestions, Pat
From: us on
"Patrick " <patrick.laux(a)imk.fzk.de> wrote in message <hvd2q0$sv8$1(a)fred.mathworks.com>...
> Hello,
>
> I want to use the eval command to concatenate vectors which are created with a loop.
> Here is the code:
>
> for a=79:79 %year
> for b=1:12 %month
> [Mod_precip_hourly]=RealTS_fu('Z:\','MMSFC_dewAc.',a,b,a,b,1,63,2)
> eval(sprintf('m%d = [Mod_precip_hourly]', b));
>
> end
> end
>
> This creates 12 vectors of dim 744x1 (Jan), 672x1 (Feb), 744x1 (Mar) ... (depending on the month) which are assigned to the variables m1,...,m12.
>
> Finally, I could simply concatenate using e.g. m1979=cat(2,m1,,2,..,m12), however, I would prefer a more generic solution, e.g. depending on the numer of the available months, maybe with cat in combination with the the eval command in the inner loop? I have no idea how this will work.
>
> I would appreciate any suggestions, Pat

a hint:
- you're asking for this evergreen...

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

us