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:
problems with save(...,'-struct',...) in function format

Subject: problems with save(...,'-struct',...) in function format

From: Camille Couzi

Date: 7 Apr, 2011 14:38:20

Message: 1 of 2

Hi Matlabers!
I need some help for a little problem.
I am using save function to save a matrix with a structure:

this is my matrix (for example):
matrix_example.a=12.2;
matrix_example.b='Hi!';

Now I want to save it. if I use matlab command syntax, it is:
save myexample.mat -struct matrix_example

That works fine. The thing is that I want to save matrix_example under a file name that I compose like that:

filename='myfilename.mat';

so if I write:
save filename -struct matrix_example
it works, matlab save my matrix, but under the name filename.mat, and not mysfilename.mat!!!!!!!
ie it does not go inside filename variable and takes the string inside (myfilename.mat) !!!!

how can i solve this problem?!
using function format => save (filename, ' -struct', matrix_example) ?
I get this error:
??? Error using ==> save
The argument to -STRUCT must be the name of a scalar structure variable.

Thanks in advance for your help!

Subject: problems with save(...,'-struct',...) in function format

From: Camille Couzi

Date: 7 Apr, 2011 14:48:20

Message: 2 of 2

sorry, I autorespond, I justo found the solution:
it was:
save (filename, ' -struct', 'matrix_example')
instead of:
save (filename, ' -struct', matrix_example)

!!!

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