Why is my plot not showing anything?

조회 수: 1 (최근 30일)
Aarya O
Aarya O 2022년 6월 17일
댓글: Walter Roberson 2022년 6월 18일
I double checked the equation with a graphing calculator to verify that the plot window is appropriate. There are no syntax error messages, and to my knowledge, there is nothing glaringly incorrect about the syntax.
My code is pasted below:
x = linspace(0,10,1); %Assume the time is from 0 to 10 seconds
%Step response of a 1st-order ODE
% For the 1st order relationship, assume that:
%y_0 = 1
%Tau = 5
y_0 = 10;
Tau = 3;
y = y_0 * (1 - exp((-1*x)/Tau));
grid on
xlim([0 10])
ylim([0 10])
Thank you for your time, and I appreciate anyone who can point out what I'm doing wrong. I'm new to MATLAB so I apologize if the mistake is obvious.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 6월 17일
x = linspace(0,10,1)
The ,1 asks that the vector be length 1

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

채택된 답변

Geoff Hayes
Geoff Hayes 2022년 6월 17일
@Aarya O - consider this line
x = linspace(0,10,1);
where you say that you want 1 linearly spaced item between 0 and 10. So this means that x is just 10...and so you are plotting one point only. Try changing this to
x = linspace(0,10,100);
and you should see something different.
  댓글 수: 2
Aarya O
Aarya O 2022년 6월 17일
Hi Geoff. Thank you so much for your response. I guess I got confused by linspace syntax! I was under the impression that the second number is the upper limit and the third number is the interval, but I see now that it should be reversed. Thanks again for the help
Walter Roberson
Walter Roberson 2022년 6월 18일
First is start, second is end, third is total number of entries. First and last appear exactly unless the count is 1.
If you want interval then 0:1:10 which is first:increment:not_to_exceed . The end point will not necessarily appear. 1:1.5:3.5 would be 1, 1+1.5 and stop because 1+1.5+1.5 = 4 exceeds the upper limit of 3.5

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

추가 답변 (0개)


Help CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기





Community Treasure Hunt

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

Start Hunting!

Translated by