MATLAB / Octave Tutorial----Chapter 3-----Visualising the data(Part 2)
Chapter 3: Visualising the data
Part 2
Welcome to the second part of this chapter. In this chapter we will learn some more things about the plot function and also learn about a few more data visualizing functions.
One of the overloads of the plot function is : plot([x-data],[y-data],line-style/marker/color).
Here, line color refers to a special string which denotes the color of the line in the graph. The following table denotes the colour coding scheme in MATLAB:
Example : The following plot command prints a graph having red dotted lines:
plot(x, y, ':r')
Now, let us suppose that you need to plot another curve on the same graph, like, you want to plot the cubes of the numbers. Here's how you'll do it:
Please note that, the function hold is used to retain the previous plot and allows us to plot more points on the same graph. hold on means the previous graph will be retained. Using hold off undoes the action. By default, the hold functionality is kept off.
Now, there are other ways of visualizing the data. Instead of a linear curve, you might want discrete lines to represent the points. Or you may even want to see discrete points representing your data. MATLAB provides for your requirements.
The stem function represents the data points using discrete lines. This is shown below:
Demonstration of stem function
The scatter function generates a scatter plot of the points. This is shown below:
Demonstration of scatter function
Now, we come to the end of this part. One bonus tip: use help your-command to get help about any valid MATLAB command. Example: help plot gives you the entire documentation related to the use of the plot command.
The next part of this chapter will be the last part. In the next part you'll get to know about how to generate subplots and plot each graph on a different window. I shall also upload a piece of code on GitHub which can be used as a reference. I'll also give a simple assignment at the completion of this chapter. Happy Learning !!!
Comments
Post a Comment