Skip to content

Commit

Permalink
markdown source builds
Browse files Browse the repository at this point in the history
Auto-generated via {sandpaper}
Source  : c9f68ad
Branch  : main
Author  : Francisco Herrerías-Azcué <[email protected]>
Time    : 2023-10-18 15:07:34 +0000
Message : Merge pull request #28 from UoMResearchIT/tiledlayout

Tiledlayout
  • Loading branch information
actions-user committed Oct 18, 2023
1 parent 5a1a542 commit cf3ae34
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 79 deletions.
51 changes: 37 additions & 14 deletions 04-plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,51 @@ Then, we can use the instruction `hold on` to add a plot for patient_5.
Remember to tell matlab you are done by adding `hold off` when you are done!


## Subplots
## Multiple plots in a figure

It is often convenient to combine multiple plots into one figure.
The `subplot(m,n,p)`command allows us to do just that.
The first two parameter define a grid of `m` rows and `n` columns,
in which our plots will be placed.
The third parameter indicates the position on the grid that we want to use for the "next" plot command.
It is often convenient to show different plots side by side.
The [`tiledlayout(m,n)`](https://mathworks.com/help/matlab/ref/tiledlayout.html) command allows us to do just that.
The first two parameter define a grid of `m` rows and `n` columns in which our plots will be placed.
To be able to plot something on each of the tiles, we use the [`nexttile`](https://mathworks.com/help/releases/R2019b/matlab/ref/nexttile.html) command.
For example, we can show the average daily min and max plots together with:
```matlab
>> subplot(1, 2, 1)
>> tiledlayout(1, 2)
>> nexttile
>> plot(per_day_max)
>> ylabel('max')
>> xlabel('day')
>> title('Max')
>> xlabel('Day of trial')
>> ylabel('Inflamation')
>> nexttile
>> plot(per_day_min)
>> title('Min')
>> xlabel('Day of trial')
>> ylabel('Inflamation')
```
![](fig/max-min-tiledplot.png){alt='Max Min tiledplot'}

>> subplot(1, 2, 2)
We can also specify titles and labels for the whole tiled layout if we assign the tiled layout to a variable
and pass it as a first argument to `title`, `xlabel` or `ylabel`, for example:
```matlab
>> tlo=tiledlayout(1, 2)
>> title(tlo,'Per day data')
>> xlabel(tlo,'Day of trial')
>> ylabel(tlo,'Inflamation')
>> nexttile
>> plot(per_day_max)
>> title('Max')
>> nexttile
>> plot(per_day_min)
>> ylabel('min')
>> xlabel('day')
>> title('Min')
```

![](fig/max-min-subplot.png){alt='Max Min subplot'}
![](fig/max-min-tiledplot-titles.png){alt='Max Min tiledplot with shared labels'}

::::::::::::::::::::::::::::::::::::::::: callout

**Note:** The [`subplot`](https://mathworks.com/help/matlab/ref/subplot.html)
command was deprecated in favour of `tiledlayout` in 2019.

::::::::::::::::::::::::::::::::::::::::::::::::::


## Heatmaps
Expand Down Expand Up @@ -211,6 +234,6 @@ subjects of the next two lessons.
- "Document your plots with `title('My title')`, `xlabel('My horizontal label')` and `ylabel('My vertical label')`."
- "Use `hold on` and `hold off` to plot multiple lines at the same time."
- "Use `legend` and add `,'DisplayName','legend name here'` inside the plot function to add a legend."
- "Use `subplot(m,n,p)` to create a grid of `m` x `n` plots, and choose a position `p` for a plot."
- "Use `tiledlayout(m,n)` to create a grid of `m` x `n` plots, and use `nexttile` to change the position of the next plot."

::::::::::::::::::::::::::::::::::::::::::::::::::
39 changes: 18 additions & 21 deletions 05-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,25 @@ patient_data = readmatrix('data/inflammation-01.csv');
figure
% Define tiled layout and labels
tlo = tiledlayout(1,3);
xlabel(tlo,'Day of trial')
ylabel(tlo,'Inflammation')
% Plot average inflammation per day
subplot(1, 3, 1)
nexttile
plot(mean(patient_data, 1))
title('Daily average inflammation')
xlabel('Day of trial')
ylabel('Inflammation')
title('Average')
% Plot max inflammation per day
subplot(1, 3, 2)
nexttile
plot(max(patient_data, [], 1))
title('Max')
ylabel('Inflammation')
xlabel('Day of trial')
% Plot min inflammation per day
subplot(1, 3, 3)
nexttile
plot(min(patient_data, [], 1))
title('Min')
ylabel('Inflammation')
xlabel('Day of trial')
```

The script now allows us to create all 3 plots with a single command: `plot_daily_average`.
Expand Down Expand Up @@ -354,27 +353,25 @@ patient_data = readmatrix('data/inflammation-01.csv');
figure('visible', 'off')
% Define tiled layout and labels
tlo = tiledlayout(1,3);
xlabel(tlo,'Day of trial')
ylabel(tlo,'Inflammation')
% Plot average inflammation per day
subplot(1, 3, 1)
nexttile
plot(mean(patient_data, 1))
title('Daily average inflammation')
xlabel('Day of trial')
ylabel('Inflammation')
title('Average')
% Plot max inflammation per day
subplot(1, 3, 2)
nexttile
plot(max(patient_data, [], 1))
title('Max')
ylabel('Inflammation')
xlabel('Day of trial')
% Plot min inflammation per day
subplot(1, 3, 3)
nexttile
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')
Expand Down
19 changes: 9 additions & 10 deletions 06-func.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,26 +351,25 @@ function plot_daily_average(data_file,plot_name)
figure('visible', 'off')
% Define tiled layout and labels
tlo = tiledlayout(1,3);
xlabel(tlo,'Day of trial')
ylabel(tlo,'Inflammation')
% Plot average inflammation per day
subplot(1, 3, 1)
nexttile
plot(mean(patient_data, 1))
title('Daily average inflammation')
xlabel('Day of trial')
ylabel('Inflammation')
title('Average')
% Plot max inflammation per day
subplot(1, 3, 2)
nexttile
plot(max(patient_data, [], 1))
title('Max')
ylabel('Inflammation')
xlabel('Day of trial')
% Plot min inflammation per day
subplot(1, 3, 3)
nexttile
plot(min(patient_data, [], 1))
title('Min')
ylabel('Inflammation')
xlabel('Day of trial')
% Save plot in 'results' folder as png image:
saveas(gcf,plot_name)
Expand Down
16 changes: 7 additions & 9 deletions 07-loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,23 +594,21 @@ for i = 1:length(files)
% Create figures
figure('visible', 'off')
subplot(2, 2, 1)
tlo = tiledlayout(1,3);
xlabel(tlo,'Day of trial')
ylabel(tlo,'Inflammation')
nexttile
plot(mean(patient_data, 1))
title('Average')
ylabel('Inflammation')
xlabel('Day')
subplot(2, 2, 2)
nexttile
plot(max(patient_data, [], 1))
title('Max')
ylabel('Inflammation')
xlabel('Day')
subplot(2, 2, 3)
nexttile
plot(min(patient_data, [], 1))
title('Min')
ylabel('Inflammation')
xlabel('Day')
print(img_name, '-dpng')
close()
Expand Down
16 changes: 7 additions & 9 deletions 08-cond.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,21 @@ for i = 1:length(files)
figure('visible', 'on')
end
subplot(2, 2, 1)
tlo = tiledlayout(1,3);
xlabel(tlo,'Day of trial')
ylabel(tlo,'Inflammation')
nexttile
plot(mean(patient_data, 1))
title('Average')
ylabel('Inflammation')
xlabel('Day')
subplot(2, 2, 2)
nexttile
plot(max(patient_data, [], 1))
title('Max')
ylabel('Inflammation')
xlabel('Day')
subplot(2, 2, 3)
nexttile
plot(min(patient_data, [], 1))
title('Min')
ylabel('Inflammation')
xlabel('Day')
if plot_switch == 1
print(img_name, '-dpng')
Expand Down
Binary file added fig/max-min-tiledplot-titles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/max-min-tiledplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"episodes/01-intro.md" "3fac099664ec6da60ddb43bc55819a6b" "site/built/01-intro.md" "2023-10-18"
"episodes/02-arrays.md" "0d384dc0236a9aee44374f46d550f6dc" "site/built/02-arrays.md" "2023-10-18"
"episodes/03-loading_data.md" "02fb4fad8914f6010205f6002eb699db" "site/built/03-loading_data.md" "2023-10-18"
"episodes/04-plotting.md" "12d5b8ceb9356a34cd804e279637d216" "site/built/04-plotting.md" "2023-10-18"
"episodes/05-scripts.md" "345b218b165e690c05526faa0fd9e276" "site/built/05-scripts.md" "2023-06-28"
"episodes/06-func.md" "05ba07f8d1501cd0bff5588fa0e29412" "site/built/06-func.md" "2023-10-18"
"episodes/07-loops.md" "85de3b8735b0c68d274bb989c33c0f81" "site/built/07-loops.md" "2023-06-28"
"episodes/08-cond.md" "ad6e520c143ce719c701765c05ef4cb3" "site/built/08-cond.md" "2023-06-28"
"episodes/04-plotting.md" "f74ca3064ff3b6fa70ba20922ee98890" "site/built/04-plotting.md" "2023-10-18"
"episodes/05-scripts.md" "65770335e6794222572dbbeb526984dc" "site/built/05-scripts.md" "2023-10-18"
"episodes/06-func.md" "a2d5b02ad26258bc6fcec3c955b78fc9" "site/built/06-func.md" "2023-10-18"
"episodes/07-loops.md" "918e58912b1b5ff11f3b78ff0bb2e53b" "site/built/07-loops.md" "2023-10-18"
"episodes/08-cond.md" "d2c7126d491fa34b663d3fdfc210b53e" "site/built/08-cond.md" "2023-10-18"
"instructors/instructor-notes.md" "95bc9dd61103b3d6345f9d96dce4538b" "site/built/instructor-notes.md" "2023-10-18"
"learners/discuss.md" "e7d00cb8aa5e7de1aaaa659777dad8d4" "site/built/discuss.md" "2023-06-28"
"learners/reference.md" "d0657233bd22009b22cce42e8ee043cb" "site/built/reference.md" "2023-10-18"
"learners/reference.md" "a0448de45fac7449fb27497c4214b10a" "site/built/reference.md" "2023-10-18"
"learners/setup.md" "e86013e5580010eb2b0c7f73c7a4ea27" "site/built/setup.md" "2023-06-28"
"profiles/learner-profiles.md" "60b93493cf1da06dfd63255d73854461" "site/built/learner-profiles.md" "2023-06-28"
15 changes: 5 additions & 10 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
title: 'Learning resources'
---

[Matlab online](mathworks.com/products/matlab-online.html) lets you use the software for free, which can be useful when you do not have access to the university licences.
[Matlab online](https://mathworks.com/products/matlab-online.html) lets you use the software for free, which can be useful when you do not have access to the university licences.

The [totorials section](https://uk.mathworks.com/support/learn-with-matlab-tutorials.html)
The [totorials section](https://mathworks.com/support/learn-with-matlab-tutorials.html)
on MATLAB's site also lists useful video tutorials and examples to work through.

[MATLAB Academy](matlabacademy.mathworks.com/)
[MATLAB Academy](https://matlabacademy.mathworks.com/)
provides a lot of self-taught material and free courses.
In particular, the [Onramp](matlabacademy.mathworks.com/details/matlab-onramp/gettingstarted) program covers material similar to this course.
In particular, the [Onramp](https://matlabacademy.mathworks.com/details/matlab-onramp/gettingstarted) program covers material similar to this course.

[Matlab cody](mathworks.com/matlabcentral/cody) can be a good way to keep practicing and find interesting challenges to learn how to code with MATLAB.
[Matlab cody](https://mathworks.com/matlabcentral/cody) can be a good way to keep practicing and find interesting challenges to learn how to code with MATLAB.


## Glossary
Expand Down Expand Up @@ -103,11 +103,6 @@ For example, the statement `x += 3` means the same thing as `x = x + 3`.
[integer]{#integer}
: A whole number, such as -12343. See also: [floating-point number](#floating-point-number).

[invariant]{#invariant}
: An expression whose value doesn't change during the execution of a program,
typically used in an [assertion](#assertion).
See also: [precondition](#precondition), [postcondition](#postcondition).

[library]{#library}
: A family of code units (functions, classes, variables) that implement a set of
related tasks.
Expand Down

0 comments on commit cf3ae34

Please sign in to comment.