Putting alpha in a string

17 Ansichten (letzte 30 Tage)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA am 21 Apr. 2022
Kommentiert: Voss am 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)');

Akzeptierte Antwort

Matt J
Matt J am 21 Apr. 2022
Bearbeitet: Matt J am 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 Kommentare
Matt J
Matt J am 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 am 21 Apr. 2022
Thank you very much for the help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Voss
Voss am 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 Kommentare
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA am 21 Apr. 2022
Thank you. the 10^6 has to go after the M_s.
Voss
Voss am 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)');

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by