Use a character variable for a title in a plot function
古いコメントを表示
Hello, I would like to use a pre-defined variable within the title of a plot function. The code that doesn't work is:
Site = char('LabX');
Then within the function itself:
title([Site ', MeanRespValues']);
This returns the error:
Undefined function or variable 'Site'.
Error in plotFunction (line 28)
title([Site ', MeanRespValues']);
Ideally, in the function's prompt it could ask for a site name to be entered, rather than creating a variable.
I'm looking to return a plot with the title "LabX, MeanRespValues".
I appreciate any help you can throw my way.
採用された回答
その他の回答 (1 件)
Balsip
assuming LabX is type double, uint, ..
use
Site=num2str(LabX)
no need for '' around the variable LabX
the reason is that the function char() doesn't cast the type you want, it produces the character that according to ASCII table has for numeric value 3.
if you find these lines useful would you please mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
2 件のコメント
balsip
2017 年 1 月 16 日
Image Analyst
2017 年 1 月 16 日
Like I said, the FAQ shows you how to do it.
カテゴリ
ヘルプ センター および File Exchange で Title についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!