You can add simple annotations to your plots like titles, x and y axes titles and labels, and a legend.
- [Narrator] Now that we have our plot looking pretty let's add some annotations to it. Let's go down to the bottom of our plot area here. And one thing we should also do is turn a hold off when we're done. We don't want to end up writing our plot data to anything other than figure one. Let's type in a label for the x axis. We'll do x label, that's the command we use for that. In this function we pass it a string. We'll say, time in seconds.
That should work. We can do a similar thing for the y axis. Let's do y label and we'll call this air speed. We're good physicists so we always need to put our units. Let's do meters per second. We can also add a title to our plot. Let's say, title. Once again this is function that we pass a string into. Let's call it my awesome plot. Let's go ahead and run our script and see how that looks.
Pretty good. We see air speed and meters per second, time in seconds and our title. We can also add a legend to our plot. I'm going to go ahead and close this guy. To do that let's change up our second plot here a bit. Let's get rid of our dash sign line and let's change it to little triangles which we do with a little caret symbol here. We'll change it to blue triangles. Let's make it so we can see it a little bit better too so let's make it different. Let's do point five times y. Then we'll have a little somewhat smaller amplitude sign wave in there.
Then let's go down here, it really doesn't matter where in this list we put the symbols on once the two plots are up. We'll create a legend. And our legend takes however many strings as an argument as we have for plots in our figure. Since we have two, we can call the first one a European Swallow and we'll say the second one is an African Swallow. We can see our air speed velocity of our two birds here.
Let's go ahead and run our script again. There we have it. That looks great. We can see our air speed and time, our two separate sign waves with their various markers and colors, and we have our legend up in the corner. If you check out the help documentation on legend you can also change where the legend appears in the plot or even outside the plot. There's way more options for changing the look of your plots than we can cover in this course so I encourage you to check out the documentation on the various commands.
- Creating MATLAB variables
- Working with matrix and scalar operations
- Using if statements and loops
- Creating functions
- Importing data
- Building basic plots and 3D plots
- Working with images
- Creating Simulink models