Possible to use string variable in plot title?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Azzi Abdelmalek
2013년 1월 3일
titlename='my plot'
title(titlename)
댓글 수: 2
Jan
2013년 1월 8일
Do you mean:
Data = rand(10);
newFileName = fullfile(filepath, [filename, '.processed']);
save(newFileName, 'Data');
추가 답변 (4개)
José-Luis
2013년 1월 8일
편집: José-Luis
2013년 1월 8일
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
Jan
2013년 1월 8일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!