Putting alpha in a string

18 vues (au cours des 30 derniers jours)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA le 21 Avr 2022
Commenté : Voss le 21 Avr 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)');

Réponse acceptée

Matt J
Matt J le 21 Avr 2022
Modifié(e) : Matt J le 21 Avr 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 commentaires
Matt J
Matt J le 21 Avr 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 le 21 Avr 2022
Thank you very much for the help.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by