Possible to use string variable in plot title?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Don
le 3 Jan 2013
Réponse apportée : venu gopal
le 8 Déc 2020
I would like to create a string that can be used as part of a plot title.
Is this possible? I have searched documentation and have experimented but these efforts have yielded no helpful outcome
Thanks for any help
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 3 Jan 2013
titlename='my plot'
title(titlename)
2 commentaires
Jan
le 8 Jan 2013
Do you mean:
Data = rand(10);
newFileName = fullfile(filepath, [filename, '.processed']);
save(newFileName, 'Data');
Plus de réponses (4)
José-Luis
le 8 Jan 2013
Modifié(e) : José-Luis
le 8 Jan 2013
This is a bit convoluted, and probably pointless, but it will get a string from a variable name.
Fz = rand(100,1);
fun = @(x) inputname(1); %Returns variable name, won't work for indexed variables
your_string = fun(Fz);
title(your_string); % or title(fun(Fz)); if you want it in a single line
A more elegant way would be to save your data as a structure, with one of the fields as the name and another with the actual data.
0 commentaires
Jan
le 8 Jan 2013
It is a bad idea to let the name of the variable carry the information about its contents. The name of the variable should only depend on its functionality in the algorithm.
If a program is specific to a physical model, using a name, which reflects the real-world object, is helpful. But as soon as the program gets more abstract, the names of the variables should do this also. Example:
F = m * a
Here F is the force, m the mass and a the acceleration. For a simple physical simulation these terms are perfect. But when you write an ODE solver, these names can confuse the user, e.g. when some financial transactions are simulated.
In your case the "number crunching" seems to have the critical abstraction level already, such that afterwards "Fz" and "Fx" or whatever might be confused. Therefore it is worth to store such important information explicitly:
Data(1).name = 'Fz';
Data(1).value = rand(1, 1000);
Data(2).name = 'F_filtered';
Data(2).value = filter(B, A, rand(1, 1000));
Now even after extremely complicated programs, the required information is easy to obtain and the code can be expanded easily.
The general rule is to separate the values, the information about the physical meaning and the program itself. Then the abstraction allows to apply the program for more general purposes.
0 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!