how can I use a name of an external variable in a function?

2 visualizaciones (últimos 30 días)
Hi,
with the following function:
function savefigure(data)
imagesc(data)
saveas(1,['nameofthevariabledata.png']);
I would like to the image under the name of the variable. In an example: I have a matrix "we13", so I call the function with
savefigure(we13)
and I hopefully the function saves the figure as "we13.png". I don't know how to give the name of the variable (in this case "we13") to the function, so I can use it in the function. I hope someone has an idea. Thaks a lot Jim

Respuesta aceptada

Robert Cumming
Robert Cumming el 10 de En. de 2012
help inputname

Más respuestas (2)

C.J. Harris
C.J. Harris el 10 de En. de 2012
Do you mean something like this:
function [] = savefigure( data, filename )
imagesc(data)
saveas(1, filename, 'png');
return
Then to call the function:
filename = 'we13';
savefigure(data, filename);
Edit:
If you actually want to use the name of the source variable, then the previous answer is on the right track:
function [] = savefigure( data, filename )
imagesc(data)
saveas(1, inputname(2), 'png');
return

Jim
Jim el 10 de En. de 2012
Thanks a lot. "Inputname" was the one I was looking for...

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by