How can I write a fraction inside string?

115 次查看(过去 30 天)
I have a plot where I put the graph's parameters in a string and put xlabel as the unit on X-axis. Inside the string, I need to have the below line "B-H curve at f=%d Hz with dB/dH0=%.4f with the point (B1, H1) and alpha=%.4f, c=%.2f, k=%.d" How can I write that? I have given a sample code below:
clc
clear
y=rand(100,1);
x=1:100;
plot(x,y)
str=sprintf(??????????????????????????????????????????????????????????????????????);
xlabel({'H (A/m)',str});
ylabel('B (T)');

采纳的回答

Jan
Jan 2022-5-13
编辑:Jan 2022-5-13
What exactly is the problem? I've simply copied the string provided in the question, inserted a linebreak \n to let the comnplete text be inside the limits and inserted some dummy data:
y=rand(100,1);
x=1:100;
plot(x,y)
str=sprintf(['B-H curve at f=%d Hz with dB/dH0=%.4f with the point\n', ...
'(B1, H1) and alpha=%.4f, c=%.2f, k=%.d)'], 1, 2, 3, 4, 5);
xlabel({'H (A/m)', str});
ylabel('B (T)');
Looks trivial. Do I oversee anything?
  10 个评论
ANANTA BIJOY BHADRA
I need to make a figure caption. That is my main target. I have attached an image along with the comment. Hope it helps.
Jan
Jan 2022-5-14
@ANANTA BIJOY BHADRA: We have showed you, how to display the wanted fraction as xlabel. It is trivial to insert the other part of the text by your own. So what is still the problem?
xlabel(['Put what you want here $\frac{dB}{dH0}$', ...
char(10), ' and here'], 'Interpreter', 'latex')
You got examples already for inserting values in a string
str=sprintf(['B-H curve at f=%d Hz with dB/dH0=%.4f with the point\n', ...
'(B1, H1) and alpha=%.4f, c=%.2f, k=%.d)'], 1, 2, 3, 4, 5);
All you have to do is to combine these two methods.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by