From: ben harper on
i have an easy problem.

i want to load a "mat" or "txt" file.
i use normally
"load test_no1.mat" command

can i break file name into pieces like:
file1=''test_no"
file2=2
file3=".mat"

with changing file2 variable, i can i load other mat files.
how can i do this?
thank you.
From: James Tursa on
"ben harper" <controlusc(a)gmail.com> wrote in message <hml02e$11l$1(a)fred.mathworks.com>...
> i have an easy problem.
>
> i want to load a "mat" or "txt" file.
> i use normally
> "load test_no1.mat" command
>
> can i break file name into pieces like:
> file1=''test_no"
> file2=2
> file3=".mat"
>
> with changing file2 variable, i can i load other mat files.
> how can i do this?
> thank you.

filename = [file1 num2str(file2) file3];
load(filename)

James Tursa
From: us on
"ben harper" <controlusc(a)gmail.com> wrote in message <hml02e$11l$1(a)fred.mathworks.com>...
> i have an easy problem.
>
> i want to load a "mat" or "txt" file.
> i use normally
> "load test_no1.mat" command
>
> can i break file name into pieces like:
> file1=''test_no"
> file2=2
> file3=".mat"
>
> with changing file2 variable, i can i load other mat files.
> how can i do this?
> thank you.

one of the many solutions
- SPRINTF is very versatile as it allows you to add other/recurring patterns...

fnma=sprintf('%s%-1d%s',file1,file2,file3);
load(fnam);

us