From: Eli Melaas on
Thanks for your help!
From: us on
"Eli Melaas" <eli.melaas(a)gmail.com> wrote in message <hodutp$mj5$1(a)fred.mathworks.com>...
> I would like to change the name of pre-existing variables in a for loop such as the following:
>
> for i =2:6
> UM.ET.hh0i = UM.UM0i.L4(:,17);
> UM.H.hh0i = UM.UM0i.L4(:,15);
> UM.Rn.hh0i = UM.UM0i.L4(:,5);
> UM.VPD.hh0i = UM.UM0i.L4(:,9);
> UM.Temp.hh0i = UM.UM0i.L4(:,11);
> UM.friction.hh02 = UM.UM0i.L2(:,6);
> UM.wind.hh02 = UM.UM0i.L2(:,9);
> end
>
> where I have already created UM.ET.hh02, UM.Rn.hh02, etc.
>
> Thanks!

you are NOT allowed to do this...

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

us
From: Rob Campbell on
I suspect your code is over-complicated and not properly using the Matlab language. Re-read the Matlab documentation and re-think your approach. To spell out the exact solution to what you're trying to do (but possibly shouldn't be doing):

for i = 2:6
tmp=sprintf('UM0%d',i);
UM.ET.hh0i = UM.(tmp).L4(:,17);
end

you could also have done the slightly more explicit-looking:
tmp=['UM0',num2str(i)];

This (tmp) notation is described in the Matlab help under the section dealing with structures.