Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Dynamic Variable Name

Status
Not open for further replies.

AK1984

Structural
Apr 17, 2012
11
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
 
Replies continue below

Recommended for you

Is there something lacking in Matlab's help files on string functions and operations?

TTFN
faq731-376
7ofakss
 
Use an array. Something like:

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

Hope that heeeeeeeeeeelps.
 
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
 
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:
files = dir('Filename*.out');
for n=1:length(files)
    data{n}=importdata(files(n).name)
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor