Under the heading 'Writing MATLAB Scripts', given that we are focusing of software/data carpentry, I feel it is essential we include a more detailed example for plotting data. While the current example takes the user through the very basics of plotting in MATLAB, instructions on how to co-plot data, specify line styles, and basic manipulation of other plotting parameters will be very useful.
An example code that can introduce the above mentioned concepts using data from 'inflammation-01.csv' is given below:
% script analyze.m
patient_data = csvread('inflammation-01.csv');
disp(['Maximum inflammation: ', num2str(max(patient_data(:)))]);
disp(['Minimum inflammation: ', num2str(min(patient_data(:)))]);
disp(['Standard deviation: ', num2str(std(patient_data(:)))]);
ave_inflammation = mean(patient_data, 1);
%% Find the number of rows
no_of_patients = size(patient_data,1);
arr_of_patients = [1:1:no_of_patients]; % This can introduce the concept of building sequential arrays
%% Plot
% Open figure
figure()
hold all
grid on
% Plot data
plot(arr_of_patients,ave_inflammation,'-');
plot(arr_of_patients,max(patient_data, [], 1),'--','linewidth',2);
plot(arr_of_patients,min(patient_data, [], 1),'-.','color','r');
% Label axis
xlabel('Patient Number')
ylabel('Degree of Inflammation')
% Scale axis
set(gca,'xlim',[0 6])
set(gca,'xtick',[0:1:6])
set(gca,'ylim',[0 20])
set(gca,'ytick',[0:4:20])
% Legend
plen = legend('Average Inflammation','Max. Inflammation','Min. Inflammation')
set(plen,'location','NorthEast')
% save plot to disk as png image:
print ('patient_data-01','-dpng','-r400') % Example to specify type and quality of image