using predefined string for savefig

Im new to matlab so sorry about this.
I am trying to save a figure within a subroutine. The string to be used in the file name already exists. I know i could simply type it in but the filename depends on the parameters used in the particular data set; and there are 150 data sets.
the comands are as follows
fileparams = ['50psi_10A_Sawtooth_05Hz']
savefig(fileparams)
I get an error: "Undefined function or method 'savefig' for input arguments of type 'char'."
I have tried changing it to a cell string array and i get: "Undefined function or method 'savefig' for input arguments of type 'cell'."
How can i resolve this?
Jairo

 Respuesta aceptada

Marta Salas
Marta Salas el 27 de Mzo. de 2014
fileparams = ['50psi_10A_Sawtooth_05Hz']
filename = [fileparams '.fig']
print(filename)

7 comentarios

Jairo
Jairo el 27 de Mzo. de 2014
Thanks. Exactly what i was looking for!
Jairo
Jairo el 27 de Mzo. de 2014
Ok well almost; it saves it as a .fig but it is unable to open it and i get an error dialog stating that it is not a binary MAT -file
Marta Salas
Marta Salas el 27 de Mzo. de 2014
Editada: Marta Salas el 27 de Mzo. de 2014
Jairo
Jairo el 27 de Mzo. de 2014
it happens from windows explorer and from matlab when i doubleclick it on the upper left
Jairo
Jairo el 27 de Mzo. de 2014
open('50psi_10A_Sawtooth_05Hz_P3P4.fig')
??? Error using ==> open at 163 Unable to read MAT-file Q:\~~~\50psi_10A_Sawtooth_05Hz_P3P4.fig: not a binary MAT-file. Try LOAD -ASCII to read as text.
Try this one instead of print
saveas(gcf,filename)
Jairo
Jairo el 28 de Mzo. de 2014
There it is! thanks again.

Iniciar sesión para comentar.

Más respuestas (1)

Joseph Cheng
Joseph Cheng el 27 de Mzo. de 2014
What you have should work. The only thing that could get in the way is if you have a user-defined function that is also called savefig() within the search path of Matlab. Try
edit savefig
if it asks if you want to create it then you do not have another copy somewhere. If you are able to open it and "edit" it (i wouldn't edit it) then it might not be the same MATLAB savefig.

4 comentarios

Jairo
Jairo el 27 de Mzo. de 2014
It asks me to create it
Jairo
Jairo el 28 de Mzo. de 2014
when i type in savefig it doesnt even recognize the function. Could it be because i am using an educatiuonal version?
Jairo
Jairo el 28 de Mzo. de 2014
I am currently talking to Matlab tech to see what the problem is.
Joseph Cheng
Joseph Cheng el 28 de Mzo. de 2014
you should also look to see if the "set paths" are correct. (Files menu->Set paths) see if there are many many entries form C:\programfiles\Matlab\version\tool boxes etc.

Iniciar sesión para comentar.

Categorías

Más información sobre Printing and Saving en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Mzo. de 2014

Comentada:

el 28 de Mzo. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by