What’s the difference between the functions plot and line in MATLAB? Are they doing the same thing?
What’s the difference between the functions plot and line in MATLAB? Are they doing
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The functions
plotandlinedo nearly the same thing, butplotis a high-level function that may have more interaction with other graphics objects. A brief summary of high-level and low-level functions can be found here. High-level functions likeplotare likely internally calling primitive functions likelineto create their graphics, but they can also modify or interact with properties of their parent axes or figure. From the documentation forline:For example, if you call the
linefunction:MATLAB draws a red line in the current axes using the specified data values. If there is no axes, MATLAB creates one. If there is no figure window in which to create the axes, MATLAB creates it as well.
If you call the
linefunction a second time, MATLAB draws the second line in the current axes without erasing the first line. This behavior is different from high-level functions likeplotthat delete graphics objects and reset all axes properties (exceptPositionandUnits). You can change the behavior of high-level functions by using theholdcommand or by changing the setting of the axesNextPlotproperty.The
plotandlinefunctions also differently affect automatic line coloring, as show here.