Putting transfer function expression in the title of a bode plot

조회 수: 19 (최근 30일)
Hi Consider the following code snippet:
num=[1 2];
den=[1 7 49];
trans=tf(num,den);
tran=evalc(trans);
bode(trans)
Title=('Bode plot of:', tran)
I want to put the transfer function in the title in rational form as a function of s. I got it working but the title is cut off at the top of the figure window and maximising the window does not help. How can I adjust the vertical position of the title so that it will all be visible. Or is there a better way of converting the tf expression to a string variable that can be passed to the title. Many thanks for any help you can give me. Regards. Thomas

채택된 답변

Star Strider
Star Strider 2017년 5월 2일
I couldn’t reproduce your results with your code (the evalc call threw an error in R2017a), so I used the Symbolic Math Toolbox to create the transfer function for the title.
The Code
num=[1 2];
den=[1 7 49];
trans=tf(num,den);
syms s
n = sym(num);
d = sym(den);
ns = poly2sym(n,s);
ds = poly2sym(d,s);
tfsym = ns/ds;
tftitle = latex(tfsym);
figure(1)
bode(trans)
title(sprintf('Bode plot of: $$ %s $$', tftitle), 'Interpreter','latex')
The Plot
  댓글 수: 2
Thomas Gahan
Thomas Gahan 2017년 5월 3일
Hi Star Strider Thank you so much for your reply, much appreciated. It worked perfectly in the 2010b version also. I have included the code I was using as I might not have had it correct when I sent it to you yesterday evening as I was working from memory. Once again thank you so much. Regards Thomas clc num=[1 2]; den=[1 7 49]; trans=tf(num,den); tran=evalc('trans'); bode(num,den) title(['Bode Plot of',tran])
Star Strider
Star Strider 2017년 5월 3일
As always, my pleasure.
The evalc call is an option I had not considered. I could not get it to display correctly either, the reason I decided to use the Symbolic Math Toolbox and let it create the appropriate LaTeX code.

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

추가 답변 (1개)

Andoni Medina Murua
Andoni Medina Murua 2019년 12월 17일
편집: Andoni Medina Murua 2019년 12월 17일
Hi Star Strider, thanks for your reply. Solution works for me but it gives me this warning:
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
$$
\frac{\frac{4882746935387697\,s}{35184372088832}+\frac{2444881814469459}{274877906944}}{s^2+\frac{2602689349497067\,s}{35184372088832}+\frac{1385815694070911}{1099511627776}}
$$
What's the issue, could you help me? Just tried using your example, it gives the same error.
thanks, regards
Andoni
  댓글 수: 2
Star Strider
Star Strider 2019년 12월 17일
This works correctly when I run it:
tftitle = '\frac{\frac{4882746935387697\,s}{35184372088832}+\frac{2444881814469459}{274877906944}}{s^2+\frac{2602689349497067\,s}{35184372088832}+\frac{1385815694070911}{1099511627776}}';
num=[1 2];
den=[1 7 49];
trans=tf(num,den);
syms s
n = sym(num);
d = sym(den);
ns = poly2sym(n,s);
ds = poly2sym(d,s);
tfsym = ns/ds;
% tftitle = latex(tfsym);
figure(1)
bode(trans)
title(sprintf('Bode plot of: $$ %s $$', tftitle), 'Interpreter','latex')
You did not correctly format the string (that I call ‘tftitle’ here) when you posted it, so I have no idea what the original problem with it could be.
Andoni Medina Murua
Andoni Medina Murua 2019년 12월 20일
Hi Star Strider
Thanks for your reply. I copy paste what you sent and still I get the same warning, maybe it's linked with the Matlab version? I'm running 2018b.

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by