Filename IDL to Matlab Conversion

5 views (last 30 days)
Okay so I'm trying to convert a couple IDL programs into MatLab programs, I'm using the IDL2Matlab program but it seems to have some issues with certain things so i'm trying to clean them up.
My question is:
The IDL was saving a file name as such:
ival_filename = '*ival.' + smode + '.txt';
where smode is a global variable it's taking these 3 parts and using them to name files
How would I do this in matlab?
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jun 2012
ival_filename = ['*ival.', smode, '.txt'];

More Answers (1)

tlawren
tlawren on 26 Jun 2012
I'm not completely sure what you are trying to do, but if you are simply wanting to construct a string to use as a filename then that is pretty easy. Consider the following example.
fpre = 'ival'; % prefix
fext = '.txt'; % file extension
smode = pi; % as an example
% combine fpre, smode, and fext to form filename
fname = [fpre, num2str(smode), fext];
The above will yield ival3.1416.txt. Note, smode is numeric in this example. If smode is a character or string, then you can just use:
fname = [fpre, smode, fext];
I hope this answers your question.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!