How to plot a simple curve
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (7)
Matt Fig
le 4 Fév 2011
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.
Jiro Doke
le 4 Fév 2011
Modifié(e) : John Kelly
le 13 Nov 2013
3 votes
This is a very basic question and we have many places in the documentation for you to learn:
Sean de Wolski
le 4 Fév 2011
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 commentaire
Matt Fig
le 4 Fév 2011
Your code will error, Sean de. You are trying to plot different length vectors!
Doug Eastman
le 5 Fév 2011
ezplot('x^2',[1,10])
or
ezplot(@(x) x.^2,[1,10])
Erick
le 11 Sep 2014
0 votes
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

2 commentaires
the cyclist
le 11 Sep 2014
I suggest posting this as a new question, rather than burying as an "answer" to a 3-year-old question.
Yundie Zhang
le 17 Mai 2020
haha,,,,,
set x axix and y axis limits
xlim()
ylim()
le nhat
le 18 Mai 2016
0 votes
how to paint graph with data activity
1 commentaire
the cyclist
le 18 Mai 2016
I suggest posting this as a new question, rather than burying as an "answer" to a 5-year-old question.
Ademolawa John
le 29 Avr 2022
0 votes
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

Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!