Writing MATLAB Scripts
-Last updated on 2023-06-28 | +
Last updated on 2023-10-18 | Edit this page
@@ -591,26 +591,25 @@MATLAB< figure -% Plot average inflammation per day -subplot(1, 3, 1) -plot(mean(patient_data, 1)) -title('Daily average inflammation') -xlabel('Day of trial') -ylabel('Inflammation') - -% Plot max inflammation per day -subplot(1, 3, 2) -plot(max(patient_data, [], 1)) -title('Max') -ylabel('Inflammation') -xlabel('Day of trial') - -% Plot min inflammation per day -subplot(1, 3, 3) -plot(min(patient_data, [], 1)) -title('Min') -ylabel('Inflammation') -xlabel('Day of trial') +% Define tiled layout and labels +tlo = tiledlayout(1,3); +xlabel(tlo,'Day of trial') +ylabel(tlo,'Inflammation') + +% Plot average inflammation per day +nexttile +plot(mean(patient_data, 1)) +title('Average') + +% Plot max inflammation per day +nexttile +plot(max(patient_data, [], 1)) +title('Max') + +% Plot min inflammation per day +nexttile +plot(min(patient_data, [], 1)) +title('Min')
The script now allows us to create all 3 plots with a single command:
plot_daily_average
.
MATLAB< figure('visible', 'off') -% Plot average inflammation per day -subplot(1, 3, 1) -plot(mean(patient_data, 1)) -title('Daily average inflammation') -xlabel('Day of trial') -ylabel('Inflammation') - -% Plot max inflammation per day -subplot(1, 3, 2) -plot(max(patient_data, [], 1)) -title('Max') -ylabel('Inflammation') -xlabel('Day of trial') - -% Plot min inflammation per day -subplot(1, 3, 3) -plot(min(patient_data, [], 1)) -title('Min') -ylabel('Inflammation') -xlabel('Day of trial') - - -% Save plot in 'results' folder as png image: -saveas(gcf,'results/daily_average_01.png') - -close() +% Define tiled layout and labels +tlo = tiledlayout(1,3); +xlabel(tlo,'Day of trial') +ylabel(tlo,'Inflammation') + +% Plot average inflammation per day +nexttile +plot(mean(patient_data, 1)) +title('Average') + +% Plot max inflammation per day +nexttile +plot(max(patient_data, [], 1)) +title('Max') + +% Plot min inflammation per day +nexttile +plot(min(patient_data, [], 1)) +title('Min') + +% Save plot in 'results' folder as png image: +saveas(gcf,'results/daily_average_01.png') + +close()
The scripts we’ve written make regenerating plots easier, and looking at individual patient’s data much simpler, but we still need to open the @@ -782,7 +779,7 @@