×
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

Dynamic Variable Name

Dynamic Variable Name

Dynamic Variable Name

(OP)
Hi Guys,


I need to make this expression changes dynamically:

VariableX = importdata ('FilenameX.out');

where, everything is constant but the "X" is a integer number that changes from 1 to 5

for example: hello4 = impotdata ('file4.out');



Please Help Meeeeeeeeeee...

Thanks

RE: Dynamic Variable Name

Use an array. Something like:

CODE --> Matlab

var(x) = importdata(['filename' int2str(x) '.out']) 

Hope that heeeeeeeeeeelps.

RE: Dynamic Variable Name

One of the most commonly asked questions when those new to Matlab try to read multiple files.

You can use the "eval" function to construct variable variable names, but that gets you into a deep hole of confusion and terrible code.

Use cell arrays instead. Plenty of help and examples in the Matlab docs exist.

- Steve

RE: Dynamic Variable Name

It sounds as though you're trying to read a large number of files into MATLAB... maybe using the DIR command to build your list would be the way to go?

CODE --> MATLAB

files = dir('Filename*.out');
for n=1:length(files)
    data{n}=importdata(files(n).name)
end 

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