Use a character variable for a title in a plot function
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (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 Commenti
balsip
il 16 Gen 2017
Image Analyst
il 16 Gen 2017
Like I said, the FAQ shows you how to do it.
Categorie
Scopri di più su Title in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!