Hi Everybody,
I have the following problem:
I would like to load a number N of files, say something
like
for i=1:N
load filename_i.mat
...
...
end
where i is an integer (and positive) number.
Could you tell me how shall I introduce the index of
my loop into the filename?
Could you pls give me a simple example of that?
Many thanks,
Francesco
try it this way (num2str and [] ... or have a look at strcat)
filename_beginning='load filename_';
filename_ending='.mat';
for i=1:N
load([filename_beginning,num2str(i),filename_ending]);
end
Dan
> Hi Everybody,
> I have the following problem:
> I would like to load a number N of files, say something
> like
>
> for i=1:N
> load filename_i.mat
> ...
> ...
> end
>
> where i is an integer (and positive) number.
> Could you tell me how shall I introduce the index of
> my loop into the filename?
> Could you pls give me a simple example of that?
> Many thanks,
> Francesco
>
>
>
>
>
>
>
>
>
"Francesco " <fsarnari@maths.leeds.ac.uk> wrote in message
<fbf96u$i98$1@fred.mathworks.com>...
> <SNIP ... make a filename string from a number to use for load
You can use the functional format of LOAD, which accepts a
variable string as its input. You can create the contents of
the variable string on the fly. For that you can use
NUM2STR, STRCAT and [], but I found that SPRINTF is most
flexible:
i = 1 ;
varstring = sprintf('file%03d.txt',i)
load (varstring)
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.