plot function not giving any graphs?!

조회 수: 11 (최근 30일)
Preets12
Preets12 2018년 4월 28일
댓글: the cyclist 2018년 4월 28일
According to my code, there should be 4 graphs showing up but i only have one? Please clarify where the error is. Thanks!
  댓글 수: 1
dpb
dpb 2018년 4월 28일
The if statements aren't being satisfied owing to rounding of floating point values not being exact to the last bit for the various times...

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

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 28일
Because you are using if statements and only one statement can be true at a time. Remove if and write your code like this
subplot(2,2,1);
plot(x,gnp1);
xlabel('x(m)');
ylabel('Displacement(m)');
title('When t = 0.5 x Period');
hold on;
subplot(2,2,2);
plot(x,gnp1);
xlabel('x(m)');
ylabel('Displacement(m)');
title('When t = Period');
hold on;
subplot(2,2,3);
plot(x,gnp1);
xlabel('x(m)');
ylabel('Displacement(m)');
title('When t = 1.5 x Period');
hold on;
subplot(2,2,4);
plot(x,gnp1);
xlabel('x(m)');
ylabel('Displacement(m)');
title('When t = 2 x Period');
hold on;
All four graphs will be displayed.
  댓글 수: 1
the cyclist
the cyclist 2018년 4월 28일
I think you have both the issue mentioned in this answer, but also the one that dpb cites in his comment.
When you get to the point of your code where the plotting function are, t has a single value. So, at most only one of your conditional statements will be triggered. (It could be none of them, if the floating point comparison is not satisfied due to rounding.)
Were you expecting to have multiple values of t somehow, and different plots for different values? Because that is not what your code is doing.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by