eval and decimal numbers
eval and decimal numbers
(OP)
Hi Matlab Folks
Let' s say: I have LS1=[ 0 0.2 0.4 0.6]
I want to have my variable names that I introduce in for loops looks like:
Variable_LS1_P0=Mat % Mat are matrices calculated
Variable_LS1_P0.2=Mat
the command
eval(['Variable_LS1_P', num2str(LS1),'=Mat'])
does not work with Decimal LS1 values; there is any trick that I can make to make the eval function accepts decimal values.
Thanks
Sherif
Let' s say: I have LS1=[ 0 0.2 0.4 0.6]
I want to have my variable names that I introduce in for loops looks like:
Variable_LS1_P0=Mat % Mat are matrices calculated
Variable_LS1_P0.2=Mat
the command
eval(['Variable_LS1_P', num2str(LS1),'=Mat'])
does not work with Decimal LS1 values; there is any trick that I can make to make the eval function accepts decimal values.
Thanks
Sherif





RE: eval and decimal numbers
1 - Variable_LS1_P0.2 is an illegal filename to begin with. If I try to intialize the variable using...
Variable_LS1_P0.2=[1,2;3,4]
.....then I get error Missing operator, comma, or semi-colon.... pointing toward that period.
2 - My version does not concatentate strings using comma. Need strcat function. i.e. to create the string
I'd have to use
strcat('Variable_LS1_P',num2str(LS1),'=mat')
(although based on item 1, applying eval to this string would still result in an error)
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: eval and decimal numbers
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: eval and decimal numbers
Search the cell array help. A new-ish ML feature that makes DIY variable names a thing of the past.
- Steve