how to plot a point in matlab This is a topic that many people are looking for. militaria-agent.com is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, militaria-agent.com would like to introduce to you Basic data plotting in MATLAB. Following along are instructions in the video below:
And welcome to the screencast on basic data plotting matlab in this screencast. Werere going to review how the plot function works for mathematical functions and then apply process for plotting data. Were also going to learn a little bit about how to properly format a data.
Plot and then how to use arrays and the things that weve learned in the array manipulation screencast to make plots from arrays. So theres more than one way to plot data in matlab. But were gonna try to keep it simple and use the basic plot command that we saw earlier for plotting mathematical functions lets review how that function works first of all i have to if i were going to say plot.
The graph of y equals. X. Squared.
I first have to create a vector for inputs for example. X equal 1. 05.
To 10. And that would give me a vector of x values from 1 to 10 skipping by 05. And then i would have to define a vector for outputs.
Using a function. Say y equals. X.
Squared. So. Again.
What ive done is. Ive created two vectors that have the same length. You see over there in the workspace there 19.
Entries. Long and then i would simply plot my x. And my y.
We all know how that works. Theres no reason. Though why i cant make those x and y vectors manually instead of using functions.
Though and thats the heart of how i can use the plot command to plot data. So im going to go over here to wikipedia. And i have the wikipedia page for johnson county indiana.
Where im currently located and at the bottom of this wikipedia page are some data from the census bureau from 1830 all the way to the present. Lets suppose i wanted to make a time series plot where im plotting the population of johnson county from 1950 to 2010. Well this is another instance where i have inputs and outputs.
Im just merely going to create the vectors by hand instead of using a function to make them for me. So. My inputs are going to go from 1950 to 2010.
Lets go over here to matlab and do that well call it year and 1950 to 2010. And im skipping by 10 years. Each so that would be my vector for inputs and now my vector for outputs that doesnt follow a mathematical function.
So im just going to enter that in manually move this over here and scroll down. And i will simply enter in those population values by hand. Ill call it pop and 1950.
Was 26 183. Then 43 704. The principle behind what im doing here is the same as when i was using mathematical functions.
It says that i dont have a mathematical function to work with im just going to enter in a vector for outputs that is of course. The same length as the vector for inputs 1. 1.
5. 2 0. 9.
And then finally. Plus. Recent.
Census. Data. 1.
3. 9. 6.
5. 4. I see that you have seven columns in each.
And so thats good. I wouldnt be able to plot these if i didnt have that so now i can just simply type plot just like i did before and put the inputs. Which is here and the outputs.
Which is population. When i do that im going to get a nice little line graph right here so ive mentioned before the vectors in matlab you can think of them as like rows of spreadsheets. And thats really what weve done here.
Ive created a row or a column of x. Data. And a row or column of y data.
In a sort of spreadsheet and just using matlab to plot. One column of the data on one axis and the other column on the other axis. So theres really no difference between using the plot command for functions or for data.
Its just that we have to enter in things manually sometimes for the data now weird about formatting plots here this is a perfectly okay line plot. But for observed values like census data. We typically dont use continuous lines like this so im going to go back and change.
The plot here and include some plot options that make this look a little bit better. When i am. Graphing observed data like these seven data points.
I typically use just markers to represent the data on the graph rather than a straight line. So im going to go back. And report.
This and say make it a dash line with blue squares. And when i do that i have something that looks a little bit more like a data plot these little blue squares of the actual observed data and the lines are just there to show basically a trend and i can go back in and add some more options here for example. A title would be a good idea johnson county population.
And so on lets look at another example of plotting data. This time with a little bit more complicated format of my data over here in the spreadsheet. I have a collection of data that shows that tendance for the 1989 1990 season of the national basketball association on with the ticket prices for each market.
I think i would like to make a data plot that has attendance on the horizontal axis and price on the vertical axis so im plotting price versus attendance to see if theres any sort of visual relationship between price and attendance now to do this im going to evoke a few things weve learned in previous screencasts. First of all im going to create a matlab variable that contains these two columns of data. Im going to go over here to my workspace click on new variable.
And this is called as nba right now. It has nothing in it im going to double click. Though and bring up the editor and ill go back over to my spreadsheet and just copy out only the numerical data that i have here copy go to my matlab editor paste the excel data n.
And just to scroll down i see that these two vectors have the same length. So im going to close this out. And i see mba is a 27 by 2 matrix.
Its an array now lets try to create our data plot. Were going to go over here and remember i wanted to have a tendency on the x axis. The horizontal axis and price on the y axis.
So im going to do all this in an em file have a little bit more control over what im doing now. Attendance is the first column of my mba variable. So im just going to create a separate variable for this called attendance and im just going to set it equal to the first column of nba and remember from the array manipulation screencast that is mba parentheses.
Colon comma 1 to strip out the first column of the nba matrix there and price is the second column mba colon 2. When putting semicolons at the end because i dont want those vectors to echo back to the screen once i strip them out now. Im just simply going to plot attendance versus price and now when i sic when i run this its going to ask me to save it im lets call it mba tests or mba plot is better and when i get the plot up here.
Its going to look like kind of a mess because these are all disjointed points. That arent necessarily supposed to be connected. But matlab defaults to connect to show no markers at all and connect all the points with blue lines.
Thats not really the look that i want i think the plot is correct. Because the data are going to be scattered all over the place you can see that from the spreadsheet. But i dont think i want to connect them with ones.
It doesnt make a lot of sense. So i would like to change. This plots that there are no lines at all and maybe black squares.
Where the markers are supposed to be so i can do that by going over and inside the plot command pass a plot option to it and then single quotes normally if i wanted to say a dashed line. I would put two dashes here or if i wanted a dot dotted line. I put a dot here.
I want no lines. I just simply pass it no options here and give it the color that i want say black thats k and then give it the markers style that i want i think im going to use squares here so im put s. So what this is going to do is create a plot with no lines in it and just a bunch of little black squares and this is a nice.
What we normally call a scatter plot. And there is there are other ways to produce scatter plots in matlab. But we can do all these plotting needs here from this one plot command.
This is a pretty good plot. Lets go back and add a few more things to it to make it nice flap title and the attendance versus ticket price. They land up at the top and then label the axes x.
Label. This is already shown as in in tens of thousands. So i dont necessarily specify the units here.
Ill put attendance. And that is measured in people. And the y label is the price ticket price and that of course is measured in dollars.
And it might be helpful to to put a grid on this soft just like grid on throw that up there and now we have a nice looking plot that shows a little bit of a linear trend with a few outliers. So some markinson have very low ticket prices. A lot of attendance and vice versa.
So heres one that has fairly sort of average attendance. But a very high ticket price so lets recap. What we learned the screencast basically.
We learned that the process for plotting data is essentially the same thing as the process for plotting functions. I still have to create a vector for inputs and a vector for outputs and then call the plot command using whatever options. I want the only difference is i might have to enter in those vectors manually depending on how the data look secondly.
I can format these data plot the right way to do this is by using markers for the data points. And then either no lines whatsoever or very faint dash lines to indicate dis connections between the observed data thats all thanks for watching. .
Thank you for watching all the articles on the topic Basic data plotting in MATLAB. All shares of militaria-agent.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.