how to convert a matlab variable name to a char for use in a title, legend, etc
38 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tamar Hoory
el 5 de Dic. de 2024 a las 7:55
Comentada: Walter Roberson
el 5 de Dic. de 2024 a las 9:23
this is something that seems really basic and useful that I can't understand how to do, or find a previous answer here.
I have a matlab method that accepts some matlab matrix. This matrix has a name, of course.
Inside the method, i want to use that name in a plot's title, so it has to be converted to a char.
how do i do this conversion?
an example to clarify my question:
function(input_matrix)
figure;plot(1:100, input_matrix(:,2)); %just arbitrary example...
title('xxxx')
end
--> how do i get 'xxxx' to be the characters of input_matrix?
maybe I am missing something very simple...
thanks!
0 comentarios
Respuesta aceptada
Stephen23
el 5 de Dic. de 2024 a las 8:06
Editada: Stephen23
el 5 de Dic. de 2024 a las 8:07
function(input_matrix)
in_name = inputname(1);
...
title(in_name)
end
2 comentarios
Walter Roberson
el 5 de Dic. de 2024 a las 9:23
Note that if the input to the function is an expression at all, rather than a plain unindexed variable name, then inputname will return empty.
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!