Possible to use string variable in plot title?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Azzi Abdelmalek
il 3 Gen 2013
titlename='my plot'
title(titlename)
2 Commenti
Jan
il 8 Gen 2013
Do you mean:
Data = rand(10);
newFileName = fullfile(filepath, [filename, '.processed']);
save(newFileName, 'Data');
Più risposte (4)
José-Luis
il 8 Gen 2013
Modificato: José-Luis
il 8 Gen 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 Commenti
Jan
il 8 Gen 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 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!