Thread Subject: simple syntax problem

Subject: simple syntax problem

From: hossein darbandi

Date: 24 Jan, 2008 17:44:04

Message: 1 of 4

This is a simple syntax problem, but I can’t find it in
Matlab.

I need to run and load different mat files into my
workspace as program runs.
for example in iteration 1 (say i=1)
   load myfile1 params
iteration 2
   load myfile2 params

In programming language we simply use something like
   fileName = ['myfile' '1']
then fileName will be equal to myfile1, but if we use
   load fileName
then Matlab complains the fileName does not exist.

I had done it before, but I cannot remember it now. There
is a combination of prefix to tell Matlab that the
contents of fileName should be used not fileName itself.

anyone knows the syntax?

Thanks,
Hossein

Subject: simple syntax problem

From: Steven Lord

Date: 24 Jan, 2008 18:05:00

Message: 2 of 4


"hossein darbandi" <hosseinb@ece.ubc.ca> wrote in message
news:fnaip3$92v$1@fred.mathworks.com...
> This is a simple syntax problem, but I can’t find it in
> Matlab.
>
> I need to run and load different mat files into my
> workspace as program runs.
> for example in iteration 1 (say i=1)
> load myfile1 params
> iteration 2
> load myfile2 params
>
> In programming language we simply use something like
> fileName = ['myfile' '1']
> then fileName will be equal to myfile1, but if we use
> load fileName
> then Matlab complains the fileName does not exist.

Use the function form described in HELP LOAD instead of the command form:

load(fileName)

--
Steve Lord
slord@mathworks.com


Subject: simple syntax problem

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 24 Jan, 2008 18:10:17

Message: 3 of 4

In article <fnaip3$92v$1@fred.mathworks.com>,
hossein darbandi <hosseinb@ece.ubc.ca> wrote:
>In programming language we simply use something like
> fileName = ['myfile' '1']
>then fileName will be equal to myfile1, but if we use
> load fileName
>then Matlab complains the fileName does not exist.

>I had done it before, but I cannot remember it now.

load(fileName);
--
   "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

Subject: simple syntax problem

From: Anh Huy Phan

Date: 24 Jan, 2008 18:17:04

Message: 4 of 4

"hossein darbandi" <hosseinb@ece.ubc.ca> wrote in message
<fnaip3$92v$1@fred.mathworks.com>...
> This is a simple syntax problem, but I can’t find it in
> Matlab.
>
> I need to run and load different mat files into my
> workspace as program runs.
> for example in iteration 1 (say i=1)
> load myfile1 params
> iteration 2
> load myfile2 params
>
> In programming language we simply use something like
> fileName = ['myfile' '1']
> then fileName will be equal to myfile1, but if we use
> load fileName
> then Matlab complains the fileName does not exist.
>
> I had done it before, but I cannot remember it now. There
> is a combination of prefix to tell Matlab that the
> contents of fileName should be used not fileName itself.
>
> anyone knows the syntax?
>
> Thanks,
> Hossein
>

If you're sure that your datafile myfile1.mat already exists
in the current directory, ...

%load x,y in myfilei.mat (i = 1, 2 ...)
load(sprintf('myfile%d',i),'params');


Otherwise, you shoule use fullfile function to build full
filename (directories and filename).

HTH
Anh Huy Phan
RIKEN - BSI



Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

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 Disclaimer prior to use.

Contact us at files@mathworks.com