Saturday, September 19, 2015

Matlab Tutorial Part 5 - Plots

In today's post I want to give a short introduction into the creation of plots with Matlab. It will only be a short summary, for more details I refer to the documentation of Matlab.  There all kinds of plots are listed with parameters, it is explained for example how to label axis, change colors etc.
Here I want to describe 2 kinds of 2 - dimensional plots, namely line and bar plots, as well as the 3 -dimensional surface plot.
We create a line plot with the function plot(). For this we first create some test data via x = rand(8, 1), a new vector with 8 random values between 0 and 1.
Then plot(x) gives us the following result:

bar() creates a bar chart from the given data. bar(x) looks as follows:

Now to a 3 - dimensional plot, the surface plot. This displays (for example) an inputted 2 -dimensional matrix in the third dimension (through height and color). On the point with the coordinates (i, j) thus the (i, j)th - entry of the matrix is displayed, meaning its value is represented by the z - coordinate and additionally colored corrrespondingly.
As an example via A = rand(32) we create a random 32 x 32 matrix. surf(A) then creates the following diagram:

1 comment: