**Plotting Data on Graphs**

**Plotting Data on Graphs**

So I have thought of a new topic to discuss on Matlab Tutorial, that can help everyone out there make a better visual representation of their data that they are working with on Matlab. I am going to teach everyone how to make graphs. Now graphs are pretty simple to make, but there are a lot of extra little features you can add to make your graphs more colorful and easier on the eyes.

First, to understand what exactly we can plot. So far the only thing I have perfected is plotting two variables on an X-Y axis. To do this, you most have two arrays or sets of data (both of the same size) that are defined in the program first. After you have the variables labeled and defined, then type plot (X,Y) , where X is the label of your independent variable vector or array.

Now that you have your beautiful graph, you should put some other features on it to add just a little more customization to your Matlab graph. One thing that you should do just as a rule of thumb is have a title for the graph. The title usually should be relevant to the axes or what the graph is showing, but virtually anything can be written. The syntax for this command is title ('Your Title!') . It is *important *to write the '' in your syntax, otherwise the text won't show up.

Another good thing to add to your graph for informational and entertainment-al purposes is to also label your X and Y axes. This can be done by writing xlabel ('Your X Label Here!') or ylabel ('Y Label Here!') in your syntax. Again, keep the '' in there and make the labels somewhat relevant to your graph. Usually it is best to write down the axes' variables and their units.

For the instances that you want to graph multiple graphs on one plot, you have to use the hold command to keep them together and not on seperate graphs. First you must plot the first graph using the previously learned plot command. The next command that should be used is the hold command which starts with hold on, the second plot, and then finally hold off. The hold on tells Matlab to keep the graph being used for the first graph to stay in place. Essentially, you could have as many graphs as you want on one plot, but that would get complex and messy, especially using multiple axis ranges and variables. The "hold off" is used to turn off the hold command for any other commands you use in the program to not be plotted in the same display.

After you master these simple things, I can show you ways to change the graphs colors and and legends and other cool things!!! OK honestly, it's not THAT cool, but it is nice to see something that *you* created on the screen. It gives you a sense of accomplishment. Well till the next exciting addition of Matlab Tutorial, you stay classy San Diego!

References: University of Florida Matlab page; University of Michigan Engineering Matlab page; MathWorks Resource Page

## No comments:

Post a Comment