How to join variables in the title of plot?
Mostrar comentarios más antiguos
I am using the matlab lines as follows
title(['PCA scores', method, par]);
where method and par keep on changing for different plots. I want to join 'PCA scores' with method and par in one line. I am attaching the title of plot and request you to kindly suggest me how to join them in one line.
Deva
3 comentarios
Devendra
el 18 de Abr. de 2024
Rohit Kulkarni
el 18 de Abr. de 2024
What are the data types of method and par?
Respuestas (2)
VBBV
el 18 de Abr. de 2024
title(['PCA scores', num2str(method), num2str(par)]);
8 comentarios
VBBV
el 18 de Abr. de 2024
Assuming method & par are numeric values that change/take different values
Devendra
el 18 de Abr. de 2024
Devendra
el 18 de Abr. de 2024
If they are not numeric, then you could use string and set the FontSize to 8 (smaller) if the text in method and par variables are long enough .
title([string(PCA scores), string(method), string(par)],'FontSize', 8); %
Devendra
el 18 de Abr. de 2024
Devendra
el 18 de Abr. de 2024
Devendra
el 18 de Abr. de 2024
VBBV
el 18 de Abr. de 2024
use
format shortG
Rohit Kulkarni
el 18 de Abr. de 2024
Hi Devendra,
To join 'PCA scores' with variables `method` and `par` in one line for a MATLAB plot title, you can use the `sprintf` function or direct string concatenation. Here are two concise examples:
Using `sprintf`:
title(sprintf('PCA scores %s %s', method, par));
Using String Concatenation (MATLAB R2016b and later):
title(['PCA scores ' method ' ' par]);
Example:
method = 'LR';
par = 'Ratoon';
% 1st method
title(sprintf('PCA scores %s %s', method, par))
%2nd method
title(['PCA scores ' method ' ' par])
Thanks
Categorías
Más información sobre Mathematics and Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!