Matlab Plotting command problem

조회 수: 1 (최근 30일)
Jacob
Jacob 2024년 2월 7일
댓글: Sulaymon Eshkabilov 2024년 2월 7일
Hello,
I am having issues plotting a plot in Matlab with the following code below.
t=0:0.01:10
t = 1×1001
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
x1=11*cos(10*t+(3*pi/8));
plot(t,x1);
hold on
x2=3*cos(10*t-(pi/2));
plot(t,x2);
hold on
x3=x1+x2;
plot(t,x3);
legend('x1(t)=11*cos(10*t+(3*pi/8))','x2(t)=3*cos(10*t-(pi/2))','x3(t)=x1+x2');
title('2.c)');
For some reason when ever I run the above I get the following error and I am unable to determine what is wrong. I tried changing the wording of the plot commands just incase they had a problem but that didn't resolve the issue.
Any help is appreciated Thanks for your time!
  댓글 수: 2
Matt J
Matt J 2024년 2월 7일
I get the following error
You seem to have omitted it.
Jacob
Jacob 2024년 2월 7일
Yes I apologize but what you guys have given me solved my issue
Thanks!

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024년 2월 7일
Even though you have not mentioned any error, there is a tiny point linked with hold on command. It needs to be followed at the end with hold off to avoid ambiguity in case you'd plot a new set of data afterwards. And use of latex for legend labels might make the plot figure better look, etc., e.g.:
figure()
t=0:0.01:10;
x1=11*cos(10*t+(3*pi/8));
plot(t,x1, 'r','LineWidth',1.5);
hold on
x2=3*cos(10*t-(pi/2));
plot(t,x2, 'g:','LineWidth',2.5);
hold on
x3=x1+x2;
plot(t,x3, 'b-.', 'LineWidth',2.0);
legend({'$x_1(t)=11*cos(10*t+(3*pi/8))$','$x_2(t)=3*cos(10*t-(pi/2))$','$x_3(t)=x_1+x_2$'}, 'Interpreter','latex');
title('(2.c)');
xlabel('$t$', 'Interpreter','latex')
ylabel('$x_1(t), x_2(t), x_3(t)$', 'Interpreter','latex')
grid on
hold off % Use hold off not to plot over this figure
  댓글 수: 2
Jacob
Jacob 2024년 2월 7일
This solved my issue.
Thanks For your help!
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024년 2월 7일
Most welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by