필터 지우기
필터 지우기

Latex, sprintf and variable that changes

조회 수: 17 (최근 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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by