×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Variable interpolation

Variable interpolation

Variable interpolation

(OP)
I would like to know how to name new variables using the value of a current variable.  In my case, I get some user input, then want to create variables using the user's input as a suffix.

rpm = input('Speed in RPM: ');
test_rpm = 2;

So, if the user entered 1000, I want the next variable to be named test_1000. I love being able to do this in Perl, and I hope it can be done in Matlab.

Thanks for the help.

RE: Variable interpolation

Look at the documentation for the "eval" function.

M

--
Dr Michael F Platten

RE: Variable interpolation

MikeyP is correct, eval will do it.
try
eval( [ 'test_', int2str( round( rpm ) ), ' = ', int2str( round( rpm ) ) ] )

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!


Resources