Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
saving mat files

Subject: saving mat files

From: Jonathan

Date: 2 Mar, 2011 19:32:23

Message: 1 of 3

I have the following script for automatically saving .mat files...

fname=sprintf('Rck%d',i);
% where i varies numerically reflecting different files of interest
save([fname '.mat']);

The problem I'm having is that this saves all variables. What I can't figure out how to do is the correct format for saving a single variable. Doing it manually its as simple as:

save *.mat variable

I tried various combinations using the initial approach but none seem to work. Any help would be much appreciated.

Thanks
Jon

Subject: saving mat files

From: Think two, count blue.

Date: 2 Mar, 2011 20:11:39

Message: 2 of 3

On 11-03-02 01:32 PM, Jonathan wrote:
> I have the following script for automatically saving .mat files...
>
> fname=sprintf('Rck%d',i); % where i varies numerically reflecting different
> files of interest
> save([fname '.mat']);
>
> The problem I'm having is that this saves all variables. What I can't figure
> out how to do is the correct format for saving a single variable. Doing it
> manually its as simple as:
> save *.mat variable
>
> I tried various combinations using the initial approach but none seem to work.
> Any help would be much appreciated.

save([fname '.mat'], 'variable');

Subject: saving mat files

From: Jonathan

Date: 2 Mar, 2011 20:37:05

Message: 3 of 3

"Think two, count blue." <roberson@hushmail.com> wrote in message <ikm89s$ood$2@nrc-news.nrc.ca>...
> On 11-03-02 01:32 PM, Jonathan wrote:
> > I have the following script for automatically saving .mat files...
> >
> > fname=sprintf('Rck%d',i); % where i varies numerically reflecting different
> > files of interest
> > save([fname '.mat']);
> >
> > The problem I'm having is that this saves all variables. What I can't figure
> > out how to do is the correct format for saving a single variable. Doing it
> > manually its as simple as:
> > save *.mat variable
> >
> > I tried various combinations using the initial approach but none seem to work.
> > Any help would be much appreciated.
>
> save([fname '.mat'], 'variable');

Thanks, this worked.

Tags for this Thread

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.

Contact us