# Pass the text of fprintf to the plot's text

9 Ansichten (letzte 30 Tage)
Sim am 12 Dez. 2023
Bearbeitet: Sim am 12 Dez. 2023
Would it be possible to pass the text of fprintf to the plot's text?
x = rand(1,10);
plot(x)
m = mean(x);
sd = std(x);
a = fprintf('the mean is %1.2f\n',m);
b = fprintf('the standard deviation is %1.2f\n',sd);
text(2,0.5,[a b])
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Dyuman Joshi am 12 Dez. 2023
You will need to use sprintf for storing the char array, then using it as inputs to text().
You can either use disp or fprintf on that text for displaying it.
x = rand(1,10);
plot(x)
m = mean(x);
sd = std(x);
a = sprintf('the mean is %1.2f\n',m);
disp(a)
the mean is 0.41
b = sprintf('the standard deviation is %1.2f\n',sd);
disp(b)
the standard deviation is 0.31
text(2,0.5,[a b])
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Sim am 12 Dez. 2023
Bearbeitet: Sim am 12 Dez. 2023
thanks a lot! Yes, also using fprintf with both sentences works well as you mentioned:
x = rand(1,10);
plot(x)
m = mean(x);
sd = std(x);
a = sprintf('the mean is %1.2f\n',m);
b = sprintf('the standard deviation is %1.2f\n',sd);
text(2,0.5,[a b])
fprintf([a b])
the mean is 0.59 the standard deviation is 0.26

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by