How to join variables in the title of plot?

3 ビュー (過去 30 日間)
Devendra
Devendra 2024 年 4 月 18 日
コメント済み: VBBV 2024 年 4 月 18 日
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 件のコメント
Rohit Kulkarni
Rohit Kulkarni 2024 年 4 月 18 日
What are the data types of method and par?
Devendra
Devendra 2024 年 4 月 18 日
編集済み: Devendra 2024 年 4 月 18 日
Method is LR or RF Par is Ratoon or Plant Please suggest me how to print these variables into title of plot in one line?
Thanks for your kind cooperation.
Deva

サインインしてコメントする。

回答 (2 件)

VBBV
VBBV 2024 年 4 月 18 日
title(['PCA scores', num2str(method), num2str(par)]);
  8 件のコメント
Devendra
Devendra 2024 年 4 月 18 日
My rmse error is printed as follows
RMSE = 3.1e+02
I want to print it like
RMSE = 310
Please suggest me how to do it.
Deva
VBBV
VBBV 2024 年 4 月 18 日
use
format shortG

サインインしてコメントする。


Rohit Kulkarni
Rohit Kulkarni 2024 年 4 月 18 日
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

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by