Putting alpha in a string

17 visualizzazioni (ultimi 30 giorni)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA il 21 Apr 2022
Commentato: Voss il 21 Apr 2022
I have to make a figure caption from the m.file. The caption contains greek letters alpha. I was trying put it in thwe caption as the part of xlabel using the string command. But it does not work. I can not edit from the figure properties as I have to implement it in a loop. Also I need to put 10^6 inside the caption. How can I solve these problems? The sample code is below,
clc
clear
x=rand(10,1)
f=60
Ms_peak=1.8;
alpha=0.0001;
c=0.26;
a=1500;
k=400;
plot(x)
str=sprintf('B-H Curve at Frequency=%d for M{_s}=%.2f, \alpha=%.4f, c=%.2f, a=%d, k=%.d',f,Ms_peak,alpha,c,a,k); %Figure caption.
xlabel({'H (A/m)',str});
ylabel('B (T)');

Risposta accettata

Matt J
Matt J il 21 Apr 2022
Modificato: Matt J il 21 Apr 2022
Note the double slash in '\\alpha' as well as Interpreter='tex'.
str=sprintf('B-H Curve at Frequency=%d for M{_s}=%.2f, \\alpha=%.4f, c=%.2f, a=%d, k=%.d',f,Ms_peak,alpha,c,a,k);
xlabel({'H (A/m)',str},Interpreter='tex');
  3 Commenti
Matt J
Matt J il 21 Apr 2022
clc
clear
x=rand(10,1)
x = 10×1
0.0249 0.7662 0.7388 0.4406 0.4688 0.7279 0.9047 0.3438 0.9676 0.7423
f=60
f = 60
Ms_peak=1.8;
alpha=0.0001;
c=0.26;
a=1500;
k=400;
plot(x)
str=sprintf('B-H Curve at Frequency=%d for M{_s}=%.2f\\times10^6, \\alpha=%.4f, c=%.2f, a=%d, k=%.d',f,Ms_peak,alpha,c,a,k); %Figure caption.
xlabel({'H (A/m)',str});
ylabel('B (T)');
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA il 21 Apr 2022
Thank you very much for the help.

Accedi per commentare.

Più risposte (1)

Voss
Voss il 21 Apr 2022
Use double-backslash to escape the backslash in sprintf, so that what's returned from sprintf contains '\alpha'.
Not clear where 10^6 should go, but here it is.
clc
clear
x=rand(10,1);
f=60;
Ms_peak=1.8;
alpha=0.0001;
c=0.26;
a=1500;
k=400;
plot(x)
str=sprintf('B-H Curve at Frequency=%d for M{_s}=%.2f, \\alpha=%.4f, c=%.2f, a=%d, k=%.d',f,Ms_peak,alpha,c,a,k); %Figure caption.
xlabel({'H (A/m) [ x 10^6 ]',str});
ylabel('B (T)');
  2 Commenti
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA il 21 Apr 2022
Thank you. the 10^6 has to go after the M_s.
Voss
Voss il 21 Apr 2022
Modified, as instructed:
clc
clear
x=rand(10,1);
f=60;
Ms_peak=1.8;
alpha=0.0001;
c=0.26;
a=1500;
k=400;
plot(x)
str=sprintf('B-H Curve at Frequency=%d for M{_s}10^6=%.2f, \\alpha=%.4f, c=%.2f, a=%d, k=%.d',f,Ms_peak,alpha,c,a,k); %Figure caption.
xlabel({'H (A/m)',str}); % 'tex' is default Interpreter, not necessary to specify it
ylabel('B (T)');

Accedi per commentare.

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by