Title with multiple outputs

Here is my code:
title = (['k = %0.3f ', format(f * chord / Uinf), ...
't/T = %0.3f ', format(tInterval(t) / .5) + r, ...
'\theta_p = %0.3f ', format(theta_t(t) * 180 / pi) + r, ...
' C_Y = %0.3f ', format(float(CySto(n)))]);
Is there a way of doing this?
[EDITED, Jan, Code formatted]

回答 (2 件)

KL
KL 2017 年 11 月 20 日

1 投票

Try this,
title(['k = ' num2str(k) ' t/T = ' num2str(t/T) ' \theta_p = '...
num2str(theta_p) '\circ C_{\Upsilon} = ' num2str(C_Y)],'Interpreter','tex')

3 件のコメント

Zach Dunagan
Zach Dunagan 2017 年 11 月 21 日
編集済み: Walter Roberson 2017 年 11 月 21 日
I get a error saying T is undefined variable.
Here is the Python code I am trying to copy over to Matlab.
title='k = ' + '{:.3f}'.format(f*chord/Uinf) + ' t/T = ' + '{:.3f}'.format(tInterval[t]/.5) + r' $\theta_p$ = ' + '{:.3f}'.format(theta_t[t]*180/np.pi) + r'$^\circ$' + r' $C_Y = $' + '{:.3f}'.format(float(CySto[n]))
format(f*chord/Uinf) is a value, not a string. I know in fprintf() statements you can output a string with a integer. Can you do the same with a title?
Image Analyst
Image Analyst 2017 年 11 月 21 日
Then use
title(['k = ' num2str(k) ' t/T = ' num2str(t) ' \theta_p = '...
num2str(theta_p) '\circ C_{\Upsilon} = ' num2str(C_Y)],'Interpreter','tex')
instead.
Zach Dunagan
Zach Dunagan 2017 年 11 月 23 日
編集済み: Zach Dunagan 2017 年 11 月 23 日
I've already tried this and it doesn't work. Why are you using num2str()
If you notice in the Python code it says format(f*chord/Uinf) f, chord, and Uinf is defined are numbers.
Edit: Yes, I got it figured out!
Here is what I did...
k = f*chord/Uinf;
t_T = tInterval(t)/.5;
theta_p = theta_t(t)*180/pi;
C_Y = CySto(n);
title(['k = ' num2str(k) ' t/T = ' num2str(t_T) ' \theta_p = '...
num2str(theta_p) '\circ C_{\Upsilon} = ' num2str(C_Y)],'Interpreter','tex')

サインインしてコメントする。

Walter Roberson
Walter Roberson 2017 年 11 月 23 日

0 投票

str = sprintf('$k = %0.3f \\qquad t/T = %0.3f \\qquad \\theta_\\rho = %0.3f ^{\\circ} \\qquad C_\\gamma = %0.3f$', f * chord / Uinf, tInterval(t) / .5, theta_t(t) * 180 / pi, CySto(n));
title(str, 'interpreter', 'latex')
Please re-check, as I did not know what the '+r' was intended to indicate

5 件のコメント

Zach Dunagan
Zach Dunagan 2017 年 11 月 28 日
編集済み: Zach Dunagan 2017 年 11 月 28 日
Mine works.
Do these sets of code match? The file has both matlab and python on it. Do these sets of code line up? How would I save the image?
Walter Roberson
Walter Roberson 2017 年 11 月 28 日
No MATLAB in there.
Look at print() and saveas() and imwrite() to save images.
Zach Dunagan
Zach Dunagan 2017 年 11 月 28 日
編集済み: Zach Dunagan 2017 年 11 月 28 日
Okay, I fixed the attached file.
Zach Dunagan
Zach Dunagan 2017 年 11 月 28 日
編集済み: Zach Dunagan 2017 年 11 月 28 日
I am trying to save the figure (the subplot) in a folder on my computer. How?
EDIT: Never mind just figured it out. I had to use savefig() command.
Zach Dunagan
Zach Dunagan 2017 年 11 月 29 日
編集済み: Zach Dunagan 2017 年 11 月 30 日
Can someone please help me make these equivalent? Look at the attachment with my comments.
EDIT: Okay I manage to get almost every term to match. I don't know why xVorPs[:t] in python outputs Nan in a 28 x 1, but when I do the same for matlab I get a 30 x 1 with zeros and a number at the end.
Okay, now I have both matching. However, the python has 0.122897 at the end, while the matlab had nan. Any ideas?
Here is the Python. xVorPos[:t]=xVorPos[:t]+(np.reshape(np.dot(xSPV,x[:-1]),(t,1))+np.reshape(np.sum(xVPV*x[-1],axis=1),(t,1))+xWV*wakePanelStr+np.dot(xVV,vortStrength[:t])+Uinf*np.cos(theta_t[t]))*tStep+(h_t[t+1]-h_t[t])*np.sin(theta_t[t])
Matlab
xVorPos(1:t) = xVorPos(1:t) + reshape(mtimes(xSPV, x(1:end - 1)), [t, 1]) + reshape(sum(xVPV' * x(end)), [t, 1]) + xWV .* wakePanelStr + mtimes(xVV, vortStrength(1:t)) + Uinf .* cos(theta_t(t)) .* tStep + (h_t(t+1) - h_t(t)) .* sin(theta_t(t));
Edit: I think I manage to get it to all work now. Do you know how to save multiple figures in one folder?

サインインしてコメントする。

カテゴリ

質問済み:

2017 年 11 月 20 日

編集済み:

2017 年 11 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by