Create a plot to visualize the data.
- [Instructor] So we can do all kinds of great things with data in MATLAB, but it's no fun unless we can see it. So let's see how to create some plots. I'm going to go ahead and close out performance here, clean things up, and let's create a new script, and we'll call it plot time. Let's open that up, and let's put some of our other things that we've learned to use here. Let's go ahead and read in the data again from Sign.csv. So, let's call it myData equals and we'll do our csvread and we'll have to pull in that sign wave data.
Now if you recall, the Sine.csv has the first column as a line and the second column as a sine wave. So let's take that first column and let's set that up as our x data. So I'm going to say x equals myData and we want to just extra the first column. So we do that with a colon to grab all the rows and a one to grab column one. Let's go ahead and copy that line and let's grab our sine wave, we'll use that as the y data.
So y data will be myData, all rows, column two. Now, let's plot the data. I'm going to put a little comment in here to plot the data, and what I like to do is first open up a new figure. So if we use the command figure, that will create an empty window that we can plot stuff in. So for instance if I type it in down here in the command window, we see MATLAB brings up an empty figure and it automatically calls it figure one. If I type it again and open up another blank window, this is a nice way to keep the plots separate.
You can also force MATLAB to give a plot a specific figure number which can come in handy if you're generating a known number of plots and you want to keep them straight. If I say figure and then parenthesis ten, we'll see it'll open up a figure and call it number ten. So I'mma tell MATLAB to close all the figure windows just so I don't end up with a million of them somewhere. And then in here I'm going to do figure and just to be explicit, I'll call it figure one. So from now one, any plot commands that I make, will all be written to figure one.
So let's type plot and we'll put in our x data and our y data that we read in from the CVS and let's just leave it at that for now. We'll make it a little more fancy in a minute. So I'm going to go ahead and run this script. Here we can see our sine wave. That looks pretty good but we can make it look a lot nicer. Let's see how to do that.
- 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