Example of Hold and legend function:
Running this script will generate two individual figure windows. If there is not any other active figure window, the first, that is the bar chart, will be in the one titled in the MATLAB Figure. The second will be in next figure. See the afterward figure for both plots.
Note that the first and last points are on the axes that make them complicated to see. That is why the axis function is often used-to generate space around the points so that they are all visible.
The capability to pass a vector to a function and have the function to compute every element of the vector can be very useful in generating plots. For illustration, the script showed below graphically shows the difference between the sin and cos functions: