Thread Subject: Saving data

Subject: Saving data

From: M K

Date: 21 Jan, 2008 13:47:02

Message: 1 of 7

Hi ,

I want to be able to save data corresponding to a parameter
from running a m-file. I want to run the m-file many times
and save the results fro each run in a file and at the end
re-call them to plot them as a mesh.

For example,

I run the file and save the parameter I am interested in,
lets just call it 'x'. Now I run the file again(this time
by changing a different parameter, 'y') and save the data
of parameter 'x' again now with a different name.

So

when y=1, lets say x=1,2,3,4,5,...10000000000
when y=2, lets say x=10,20,30,40,50,.....0100000030
when y=3, lets say x=1,2,35789l,356,78,...1000000

.
.
and so on

I want to be able to save x for each value of y and then
plot them all as mesh with x depending on parameter, y and
another parameter 't' which is the same for all runs.

What command should I be using to save x , each time I run
my file?

Any help will be much appreciated!!!

Subject: Saving data

From: marky

Date: 21 Jan, 2008 13:52:43

Message: 2 of 7

M K wrote:
> Hi ,
>
> I want to be able to save data corresponding to a parameter
> from running a m-file. I want to run the m-file many times
> and save the results fro each run in a file and at the end
> re-call them to plot them as a mesh.
>
> For example,
>
> I run the file and save the parameter I am interested in,
> lets just call it 'x'. Now I run the file again(this time
> by changing a different parameter, 'y') and save the data
> of parameter 'x' again now with a different name.
>
> So
>
> when y=1, lets say x=1,2,3,4,5,...10000000000
> when y=2, lets say x=10,20,30,40,50,.....0100000030
> when y=3, lets say x=1,2,35789l,356,78,...1000000
>
> .
> .
> and so on
>
> I want to be able to save x for each value of y and then
> plot them all as mesh with x depending on parameter, y and
> another parameter 't' which is the same for all runs.
>
> What command should I be using to save x , each time I run
> my file?

Maybe the SAVE command? HELP SAVE

Subject: Saving data

From: Anh Huy Phan

Date: 21 Jan, 2008 14:10:04

Message: 3 of 7

marky <no@email.com> wrote in message
<fn286q$9rd$1@news.oulu.fi>...
> M K wrote:
> > Hi ,
> >
> > I want to be able to save data corresponding to a
parameter
> > from running a m-file. I want to run the m-file many
times
> > and save the results fro each run in a file and at the end
> > re-call them to plot them as a mesh.
> >
> > For example,
> >
> > I run the file and save the parameter I am interested in,
> > lets just call it 'x'. Now I run the file again(this time
> > by changing a different parameter, 'y') and save the data
> > of parameter 'x' again now with a different name.
> >
> > So
> >
> > when y=1, lets say x=1,2,3,4,5,...10000000000
> > when y=2, lets say x=10,20,30,40,50,.....0100000030
> > when y=3, lets say x=1,2,35789l,356,78,...1000000
> >
> > .
> > .
> > and so on
> >
> > I want to be able to save x for each value of y and then
> > plot them all as mesh with x depending on parameter, y and
> > another parameter 't' which is the same for all runs.
> >
> > What command should I be using to save x , each time I
run
> > my file?
>
> Maybe the SAVE command? HELP SAVE


You already answer your own question !!!

>> help save

By the way, there are some useful functions to genrate
automatically filenames.

  MFILENAME Name of currently executing M-file.
  FULLFILE Build full filename from parts.
  SPRINTF Write formatted data to string.

Anh Huy Phan
RIKEN - BSI


  


Subject: Saving data

From: M K

Date: 22 Jan, 2008 11:51:02

Message: 4 of 7

Thanks for replies !

So when I try saving

%%savetest is the filename and x is the variable that needs
%%to be saved

save savetest x


it gets saved as a microsoft access table under the
name 'savetest'. how could I set the filename ?

Does sprintf help me set a file name depending on the
parameter 'y'?

Why is the following not working?

fname=sprintf('output y%',y)
save fname x

and when i recall by using

load fname, it doesn't load it the way I want it to. it
only brings out the last set of x values. Any help will be
appreciated!

Subject: Saving data

From: Anh Huy Phan

Date: 22 Jan, 2008 12:36:01

Message: 5 of 7

"M K" <maha_k@mathworks.com> wrote in message
<fn4lb6$qpt$1@fred.mathworks.com>...
> Thanks for replies !
>
> So when I try saving
>
> %%savetest is the filename and x is the variable that needs
> %%to be saved
>
> save savetest x
>
>
> it gets saved as a microsoft access table under the
> name 'savetest'. how could I set the filename ?
>
> Does sprintf help me set a file name depending on the
> parameter 'y'?
>
> Why is the following not working?
>
> fname=sprintf('output y%',y)
> save fname x
>
> and when i recall by using
>
> load fname, it doesn't load it the way I want it to. it
> only brings out the last set of x values. Any help will be
> appreciated!
>

Put these lines at the end of your m file

fname=sprintf('output_y_%d',y);
save(fname,'x','y')

Each time you run this file, one new file output*.mat will be
created.

HTH
Anh Huy Phan
RIKEN - BSI

Subject: Saving data

From: Steven Lord

Date: 22 Jan, 2008 14:17:50

Message: 6 of 7


"M K" <maha_k@mathworks.com> wrote in message
news:fn4lb6$qpt$1@fred.mathworks.com...
> Thanks for replies !
>
> So when I try saving
>
> %%savetest is the filename and x is the variable that needs
> %%to be saved
>
> save savetest x
>
>
> it gets saved as a microsoft access table under the
> name 'savetest'. how could I set the filename ?

Use the function form of SAVE.

> Does sprintf help me set a file name depending on the
> parameter 'y'?
>
> Why is the following not working?
>
> fname=sprintf('output y%',y)
> save fname x

This is the command form of SAVE. It's equivalent to:

save('fname', 'x')

You need to use the functional form of SAVE when one of the string inputs is
stored in a variable, in order to pass the _contents_ of that variable
rather than _a string containing the name of that variable_ to the function:

save(fname, 'x')

For more information on the command and function calling syntaxes, read the
"MATLAB Calling Syntax" section of this documentation page:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f7-58170.html

For information on command versus function syntax as it specifically
pertains to LOAD and SAVE, read:

http://www.mathworks.com/support/solutions/data/1-16FP4.html?solution=1-16FP4

--
Steve Lord
slord@mathworks.com


Subject: Saving data

From: Daphne

Date: 22 Jan, 2008 15:31:07

Message: 7 of 7


I like using dlmwrite to save the data into a text file.
In dlmwrite you can have the data with tabs, which also
allows easy opening in excel (if needed).

You can have a count parameter ct = ct + 1 that will
update every time you run the code and then use that
number in the file name...

Daphne

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