I can't put two lines in one legend on matlab in my plot

2 Ansichten (letzte 30 Tage)
jake smith
jake smith am 19 Nov. 2015
Beantwortet: PChoppala am 1 Dez. 2015
I have a long string.
I tried to do
string1 = "xyz";
string2 = "abc";
string3 = num2str(value); //value is something I have in my script. Just using this as a placeholder.
string3 = [string3, " ", string1, string2 ];
But it doesn't print in 2 lines if I do
sprintf(string3\nstring2)
Can someone help?

Antworten (2)

dpb
dpb am 20 Nov. 2015
None of the above will work, the double quote is an illegal string delimiter in Matlab; it's a single quote (') instead.
The newline character is only recognized in formatting string expressions...
sprintf('%s\n%s',string3,string2)

PChoppala
PChoppala am 1 Dez. 2015
string1 = 'xyz';
string2 = 'abc';
value=3.14;
sprintf('%.2f %s %s \n %s',value,string1,string2,string2)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by