First time user of Matlab having issues trying to plot: y=sin x/x on an interval -30<x<30.

58 ビュー (過去 30 日間)
Below is the code below I created and when I enter it at the >> prompt in the Command window, nothing happens and no graph appears.
x=linespace(-30,30,10001);
y=sin(x)./x;
plot(x,y,'-');
axis([-30 30-1 1])
xlabel('x')
ylabel('y')
title('Fred Smith')
1-is the code correct and do I need to create an m-file ->enter the code then save -> then type in the file name at the >> prompt for it to run. I know this is very basic but I was given the assignment without ever using Matlab and I have been researching this for hours. Thanks

採用された回答

Mischa Kim
Mischa Kim 2014 年 9 月 18 日
編集済み: Mischa Kim 2014 年 9 月 18 日
Use
x = linspace(-30,30,10001);
and
axis([-30 30 -1 1])
instead. Otherwise the code looks fine. That is, copy-paste the whole thing and execute in the MATLAB command window. Alternatively, you can put the code into a script or a function and follow the steps you outlined above.
  2 件のコメント
Image Analyst
Image Analyst 2014 年 9 月 18 日
Though unless you have some super huge screen, you might use 1000 instead of 100001 because you'll never fit that many pixels on a normal screen - it will have to subsample. By the way, there is a sinc() function to do the sin(x)/x operation. Also be aware that there is a sind() function if your input is in degrees instead of radians. And, if you want, you can adjust font size like this:
fontSize = 25;
xlabel('x', 'FontSize', fontSize)
ylabel('y', 'FontSize', fontSize)
title('Fred Smith', 'FontSize', fontSize)
James
James 2014 年 9 月 18 日
Made the corrections and re ran the code and it worked like a charm. Thanks

サインインしてコメントする。

その他の回答 (1 件)

VISHNU VARDHAN REDDY B
VISHNU VARDHAN REDDY B 2020 年 10 月 5 日
fontSize = 25;
xlabel('x', 'FontSize', fontSize)
ylabel('y', 'FontSize', fontSize)
title('Fred Smith', 'FontSize', fontSize)

カテゴリ

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