フィルターのクリア

Latex, sprintf and variable that changes

11 ビュー (過去 30 日間)
Konstantinos
Konstantinos 2024 年 4 月 13 日
コメント済み: Star Strider 2024 年 4 月 13 日
Hello everyone,
In the following MATLAB code snippet:
title(sprintf('\\textbf{Product of $\\phi$ with %0.2f delayed $\\phi(t-\\%%0.2f)$ and a = %0.1f}', k(j).*T , a(i)),'Interpreter','latex');
The objective is to create a plot title combining LaTeX formatting with the value of k(j)*T. However, there seems to be an issue with the rendering of the term $\phi(t-\%0.2f)$.
What could be causing the issue in the LaTeX expression, and how can it be fixed to combine LaTeX formatting with the value of k(j)*T effectively?
Thanks in advance
The complete code:
T=1/100;
over=100;
Ts=T/over;
A=4;
a=[0,0.5,1];
k=[0,1,2];
for i=1:length(a)
[phi, t] = srrc_pulse(T,over,A,a(i));
for j=1:length(k)
figure(6*(i-1) + 2*(j-1) + 1);
hold on;
%subplot(2,1,1);
plot(t,phi);
hold on;
title(sprintf('Pulses with a = %0.1f', a(i)));
%subplot(2,1,2);
tdelayed = t+(k(j).*T);
plot(tdelayed,phi);
legend('Original \phi',sprintf('delay %0.2f', k(j).*T));
hold on;
grid on;
% Save the images
filename_subplot = sprintf('subplotWithA=%d_K=%d.png', a(i), k(j));
saveas(gcf, filename_subplot);
phioriginal = [phi zeros(1,k(j)*T/Ts)];
phidelayed = [zeros(1,k(j)*T/Ts) phi];
tmultiplication = [t(1):Ts:t(end)+k(j)*T];
figure(6*(i-1) + 2*(j));
plot(tmultiplication,phioriginal.*phidelayed);
title(sprintf('\\textbf{Product of $\\phi$ with %0.2f delayed $\\phi(t-\\%%0.2f)$ and a = %0.1f}', k(j).*T , a(i)),'Interpreter','latex');
grid on;

採用された回答

Star Strider
Star Strider 2024 年 4 月 13 日
Your sprintf statement has fields for 3 variables, however you only provide 2.
Provide all 3 and it works —
i = 1;
j = 1;
a(i) = 42;
T = 273;
k(j) = 42^3/1E3;
something_else = rand*100;
title(sprintf('\\textbf{Product of $\\phi$ with %0.2f delayed $\\phi(t-%0.2f)$ and a = %0.1f}', k(j).*T , something_else, a(i)),'Interpreter','latex');
.
  4 件のコメント
Konstantinos
Konstantinos 2024 年 4 月 13 日
I realize now that I was fixated on the variable 'something_else' and overlooked the fact that my string actually contains three variables. Thank you for your assistance, and I apologize for the misunderstanding.
Star Strider
Star Strider 2024 年 4 月 13 日
As always, my pleasure!
No worries!
No apology necessary. (I probably should have stated initially what I stated in my previous Comment. Still early here.)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by