Thoughts on the Engineering Industry

A blog covering engineering, technology and business topics

Archive for the month “April, 2013”

Matlab Commands for Creating Different Plots (part 2)

Hello everyone! I hope y’all are doing well.  Today I’m going to go into more detail about Matlab commands that can be used to label plots and change the format.  These are commands that aren’t focused on the act of opening figures or plotting data – instead these commands focus on making the plots look pretty.

xlabel(‘name’) – This command provides a label for the x axis of the chart.

ylabel(‘name’) – This command provides a label for the y axis of the chart.

title(‘name’) – This command provides a title for the plot.

Legend(‘name’,’name’,…) – This command provides labels for all the different lines plotted on the graph.  It goes in order of the plotting commands as performed – line plot 1 is the first, line plot 2 is the second, etc.

axis([xmin xmax ymin ymax]) – This command specifies a range for the x and y axis.  The data is specified in the form of a vector as shown.  There are other functions that can be done using the axis command, type ‘help axis’ to see the various functions.

These are the common labeling functions I use on a regular basis.  For details on commands that might not have been mentioned here, check out this link.  http://tinyurl.com/cb7essb  I hope these Matlab posts have been helpful.  I’m going to try and find different type topic to talk about next week.  Have a good week!

Question of the week:  How do you label your Matlab plots?  Do you have any preferences in how you do it?

Matlab Commands for Creating Different Plots

Hello everyone! I hope y’all are doing well.  Today I want to talk about some common plotting commands I use to generate sharp looking plots and save them.  I will keep it to a short length in this post and if there are more that I feel are necessary I will do it another post next weekend.  Along with that, I will do them in order that I use them in most cases.

function – This command is very simple in that it creates a new figure.  This isn’t always needed, but it is good habit to always use this command since it would leave all your figures open that you have created.

subplot(m,n,p)  –  This command allows you to place multiple plots on a single figure.  The m variable specifies the number of rows, the n variable specifies the number of columns, and the p variable specifies the location to place the following plot.  Placement goes from left to right in the top row, then down next row and from left to right, and continues in that pattern.

hold on/off – This command allows you to plot on the same figure and subplot(if used) as the previous plot without replacing the previous plot.  Use hold on to start overlay process and hold off to stop it.

plot(x,y,’a’,’b’) – This command plots a line graph.  x is the matrix that represent the horizontal variable and y is the matrix that represents the vertical variable.  The ‘a’ variable is where the code to define the color is placed.  The b variable is where the code to define the line type is placed.   Go to help plot and all the codes for the color and line type are provided.

bar(x,y) – This command creates a bar graph.  x is the matrix representing the values or labels on the horizontal axis.  y is the matrix representing the values on the vertical axis.  barh(x,y) executes the same command for a horizontal bar graph, bar3(x,y) for a 3-d bar graph, and bar3h(x,y) for a 3-d horizontal bar graph.  I am less familiar with the details of these plot commands, however, the help command should give you some more information.

pie(x) – This command creates of pie chart of the data in matrix x.  This is another command I haven’t used often; like with the bar command, the help command should give the specific details of it.

These are the commands I want to cover for today.  Next Saturday I will continue this topic with commands that can be used to label the plots and specify other details of an individual plot.  Have a good weekend!

Question of the week: Which plotting methods do you prefer?  Subplots, Layered Plots, Individual Plots or a combination of them all?  Are there certain situations you find yourself requiring use of one over another?

Post Navigation