Variable in title is appearing as random string characters.

1 回表示 (過去 30 日間)
Joe Pashley
Joe Pashley 2019 年 9 月 4 日
コメント済み: Walter Roberson 2019 年 9 月 4 日
Running matlab R2019a
Im creating a mesh plot.
Here is my code for the title:
og_rows = 15360
og_cols = 1024
title(['Form Removed Data ',og_rows, 'x', og_cols])
This is following the matlab guidelines here: https://uk.mathworks.com/help/matlab/ref/title.html
This strangely results in this:

採用された回答

Joe Pashley
Joe Pashley 2019 年 9 月 4 日
To use the format matlab reccomends, you must remember to change the number into a string. So the code would be:
title(['Form Removed Data ',num2str(og_rows), 'x', num2str(og_cols)])

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2019 年 9 月 4 日
title( sprintf('Form Removed Data %d x %d',og_rows, og_cols) )
  1 件のコメント
Joe Pashley
Joe Pashley 2019 年 9 月 4 日
編集済み: Joe Pashley 2019 年 9 月 4 日
Hey, thanks for your help.
I actually spotted my own mistake, it must be input as a string and not a number. But thanks for your answer anyway.

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


Steven Lord
Steven Lord 2019 年 9 月 4 日
Another option (instead of str2num or sprintf) is to use string operations.
og_rows = 15360;
og_cols = 1024;
title("Form Removed Data " + og_rows + " x " + og_cols)
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 9 月 4 日
(The above solution requires R2017a or later.)

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

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by