×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

eval and decimal numbers

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

RE: eval and decimal numbers

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.

RE: eval and decimal numbers

Clarification in bold:

Quote (electricpete bold clarification):


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.

RE: eval and decimal numbers

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close