Matlab_05a

More graphs and some statistics

Copy and paste the following line in to your command window and press return

my_data = [1.1 1.8 2.3 1.2 2.5; 1.3 1.7 2.8 1.9 2.0; 1.3 1.8 2.3 1.6 1.9]

We now have a matrix of data called my_data which we can use as an example. Remember how a semicolon starts a new row, so my_data is a 3-by-5 matrix. Try plotting this data:

plot(my_data)

Notice that it is the columns not the rows that have been plotted. This is a general rule in Matlab, it mostly works on data arranged in columns. If you want the rows to be plotted then you have to swap rows for columns using the transpose:

plot(my_data')

Can you spot the trends in my_data? Try this:

my_means = mean(my_data)
plot(my_means)

Matlab calculates the mean values in each column, as we have said is usually works in columns, and returns a row of results that CAN be plotted because there are no columns.

To add error bars:

my_s_errors = std(my_data)/sqrt(3)
errorbar(my_means, my_s_errors)

One more thing. We don't want to have to type the numbers again so we can save them by simply typing:

save

More on loading and saving to come.