How to plot a simple curve
294 ビュー (過去 30 日間)
古いコメントを表示
I am trying to learn MATLAB and have stumbled straight away. Can someone please tell me how you plot y = x^2 for x = 1 to 10.
0 件のコメント
採用された回答
the cyclist
2011 年 2 月 5 日
Keeping as close as possible to your notation, to be clear to you:
>> x = 1 : 0.1 : 10;
>> y = x.^2;
>> plot(x,y)
Note that the 0.1 is there to define the intervals. You'll get a smoother curve in your plot if this value is small; the vector will have correspondingly more elements.
I agree with Jiro that you will benefit from a careful read of the documents he references.
その他の回答 (7 件)
Matt Fig
2011 年 2 月 4 日
Or, if you want to be able to do this for a general function (or more):
g = @(x) x.^2; % Create your function for plotting.
h = @(x) x.^2.5; %Create a second function.
x = 1:.01:10; % Create the range for the functions.
plot(x,g(x),'r',x,h(x),'b') % Use a red line for the first, blue for second.
To only plot one function:
plot(x,g(x)) % See help plot for more options.
0 件のコメント
Jiro Doke
2011 年 2 月 4 日
編集済み: John Kelly
2013 年 11 月 13 日
This is a very basic question and we have many places in the documentation for you to learn:
0 件のコメント
Sean de Wolski
2011 年 2 月 4 日
plot(1:.1:10,1:.1:10.^2)%x = 1 to 10 with spacing of 0.1
Also read the getting started documentation.
%SCd
1 件のコメント
Matt Fig
2011 年 2 月 4 日
Your code will error, Sean de. You are trying to plot different length vectors!
Erick
2014 年 9 月 11 日
hello, how do I change my axes to have different ranges? for my graph below? and I want the curves to run from the x-axis upward to right
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175614/image.png)
2 件のコメント
the cyclist
2014 年 9 月 11 日
I suggest posting this as a new question, rather than burying as an "answer" to a 3-year-old question.
le nhat
2016 年 5 月 18 日
how to paint graph with data activity
1 件のコメント
the cyclist
2016 年 5 月 18 日
I suggest posting this as a new question, rather than burying as an "answer" to a 5-year-old question.
Ademolawa John
2022 年 4 月 29 日
hello , pls how can I plot this curve that run from top left to bottom right with Y axis running from 1 to 16 and x from 1.8 to 2.7. Thanks
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/982585/image.jpeg)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!