Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval and decimal numbers

Status
Not open for further replies.

fo2sh

Civil/Environmental
Aug 18, 2008
5
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
 
Replies continue below

Recommended for you

two comments (based on my version of Matlab = 5.2)
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.
 
Clarification in bold:
electricpete bold clarification said:
2 - My version does not concatentate strings using comma. Need strcat function. i.e. to create the string Variable_LS1_P0.2=mat

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.
 
Constructing variable names (via 'eval') and then using them will almost always end in tears. It will always end in a workspace polluted by large numbers of variables.

Search the cell array help. A new-ish ML feature that makes DIY variable names a thing of the past.

- Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor