Why is my graph coming out blank when i try and plot this code?

조회 수: 1 (최근 30일)
Christopher Saenz
Christopher Saenz 2019년 2월 23일
답변: Star Strider 2019년 2월 23일
x=[0.1:0.1:5];
y=(sin(x))/x;
figure(2)
grid on
plot(x,y)

답변 (2개)

Brian Hart
Brian Hart 2019년 2월 23일
It's an error in your calcuation of y. Check the size and you'll see it's coming out as a scalar. Replace "/" with "./", since you want element-wise division.

Star Strider
Star Strider 2019년 2월 23일
Because you are calculating a single point.
If you use element-wise division here (using ./ rather than /), you get the plot you expect:
x=[0.1:0.1:5];
y=(sin(x))./x;
figure(2)
grid on
plot(x,y)
See the documentation on Array vs. Matrix Operations (link) for an extended discussion.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by