How do I insert a variable text string in matlab plot?

조회 수: 140 (최근 30일)
Vikash Pandey
Vikash Pandey 2018년 11월 13일
편집: madhan ravi 2018년 11월 14일
Part of my code is
d_close = 3*(r1_eq + r2_eq)
figure(101);
h1 = plot(normalized_time, r1_us, 'b-', normalized_time, r2_us, 'k:');
set(h1,'linewidth',2);
txt = ['d = ', num2str(d_close)];
% t = text(0.0025, 17, txt);
t.FontSize = 24;
legend(['Bubble-1'], ['Bubble-2'])
and so on...
I wish to put sort of additional "third" legend for a plot that has two curves (r1_us and r2_us versus normalized time) only. So, I had to opt for string-method to put the additional information on the plot. But when I run the code, I get the error
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in bubble_mettin_solver (line 25)
t.FontSize = 24;
So how do I fix this? Please help. I wish that every time the plot shows up it has the information of updated d_close value.
By the way can I have a third legend in which there are only two curves? I know how to implement variable legend, but not the text.
  댓글 수: 6
Stephen23
Stephen23 2018년 11월 13일
Get rid of these square breckets:
legend(['Bubble-1'], ['Bubble-2'])
They do nothing useful whatsoever:
Vikash Pandey
Vikash Pandey 2018년 11월 13일
Agreed. removed but currently I am facing another issue.

댓글을 달려면 로그인하십시오.

채택된 답변

madhan ravi
madhan ravi 2018년 11월 13일
편집: madhan ravi 2018년 11월 14일
t=text(0.2, 21, ['d = ' num2str(d_close)]);
t.FontSize = 34;
Vikash pandey's solution:
txt = text(0.03, 21, ("$d =\mbox{ }$" + d_close*1d6 + "$\mu m$"),'Interpreter','latex');
txt.FontSize = 28;
  댓글 수: 19
Vikash Pandey
Vikash Pandey 2018년 11월 14일
Madhan. I found the solution to the problem from a user in Stackoverflow. The solution is:
txt = text(0.03, 21, ("$d =\mbox{ }$" + d_close*1d6 + "$\mu m$"),'Interpreter','latex');
txt.FontSize = 28;
madhan ravi
madhan ravi 2018년 11월 14일
wow that's cool!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jan
Jan 2018년 11월 13일
Start with omitting the clear all, because this is a waste of time only. The error message is clear: Your t is the output of ode45() and a double vector. Then you cannot define t.FontSize. In the line before, the t would have been re-defined, but it is commented:
% t = text(0.0025, 17, txt);
Either delete the "%" character there or better use a unique name for the variable:
TestH = text(0.0025, 17, txt);
TextH.FontSize = 24;
It is not clear, what a "third legend" is. There is one legend only and not even a second one. Do you want to get a third entry in this legend? This would be confusing, because readers expect the same number of lines as legend entries. Maybe an additional title helps: https://www.mathworks.com/matlabcentral/answers/324848-setting-a-title-for-a-legend
  댓글 수: 1
Vikash Pandey
Vikash Pandey 2018년 11월 13일
Thanks for the advise. I corrected it. But still a minor issue remains. Please see above.

댓글을 달려면 로그인하십시오.


Vikash Pandey
Vikash Pandey 2018년 11월 13일
Yes. you see the plot here, mu looks so different than m in the plot. I want them to be latex equally. By the way I have solved the bubble coupled ODE problem that I had posted yesterday. Hope you remember. :)
Similar_Size_Far_Radius.png

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by