Hi,
My goal is to label Xaxis and Yaxis in just one line rather in two, that is what i get.
my xlabel and ylabel are combined from two sides:
m = 5
Variable = sprintfc('Variable%d',1:m)
Variance = [10 20 30 30 10]'
when i do a plot, it plots normally what I need with my X and Y but in the xlabel part i get a 2 line label:
xlabel( Variable(1) Variance(1));
How can i turn it in only 1 line? I tried with ; in the middle doesnt work, with {} also doesnt work

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 18 Okt. 2018

0 Stimmen

xlabel( sprintf('%s%d', Variable{1}, Variance(1)) );
Though perhaps you would prefer a space between the %s and %d.

5 Kommentare

Tiago Dias
Tiago Dias am 18 Okt. 2018
Bearbeitet: Tiago Dias am 18 Okt. 2018
Thanks
1) the %s is relative to place the Variable and %d is responsible to place the value of variance?
2) MY example was unfortunate in the variance, if the Variance = [10.57 20 30 30 10]', when i do what you wrote, the value appears 1.057e+01, any way to print the "normal" value 10.57?
3) why if I wanted 3 things to be printed, what letter to choose?
%s is replaced by a character scalar or character row vector. %d is replaced by converting a numeric value into a printable decimal form.
For three values, add more %s or %d or %f or %g depending on what it was. For example,
xlabel( sprintf('%s @ %d vs %s @ %d', Variable{1}, Variance(1), Variable{2}, Variance(2)) );
Tiago Dias
Tiago Dias am 18 Okt. 2018
ok thanks
I updated this question when you replied to the previous one
MY example was unfortunate in the variance, if the Variance = [10.57 20 30 30 10]', when I do what you wrote, the value appears 1.057e+01, any way to print the "normal" value 10.57?
I recommend using %g instead of %d for those cases.
xlabel( sprintf('%s %g', Variable{1}, Variance(1)) );
Tiago Dias
Tiago Dias am 18 Okt. 2018
yeah %g, i tried %0.5g as in the example on the sprintf page
Thanks a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by