Latex, sprintf and variable that changes
조회 수: 28 (최근 30일)
이전 댓글 표시
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;
댓글 수: 0
채택된 답변
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
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 Exchange에서 LaTeX에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!