Thursday, December 31, 2015

How do you render a 2D plot in Matlab?

This is one of the most basic commands in Matlab. This provides the user with visualization of the data entered in the program (in the form of matrices or vectors) or data generated from operations in the program (while running).
The plot command has the ability of rendering a plot with a desired format, which then can be used to paste on a document.
The basic command only includes the simple instruction:
plot(x,y)
Where x and y are two different vectors of the same size. Plot will produce an error if the vectors do not have the same length (that is, equal number of objects). This is the basic form of the command, it will render a plot with no title or axes labels, the line of the plotted function will be continuous in standard black blue color.
You can add a title to the plot by typing the command title after you have issued the plot command:
plot(x,y)
title('Plot Title')
Most plots, though, will require labels on the axis (vertical abd horizontal). To achieve this, you have to enter two more commands:
plot(x,y)
title('Plot Title')
xlabel('x')
ylabel('y')
No need to add semi-colons for all these commands, unless you would like them all in one line:
plot(x,y); title('Plot Title'); xlabel('x'); ylabel('y')
Remember that text strings must be surrounded by single quotation marks.