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

2 ビュー (過去 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 Center および File Exchange2-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