Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds script to extract code from episodes and extracted code #34

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions code/01-intro.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@




% ## Introduction to the MATLAB GUI
% ## Working with variables
x = 55
y = 10
x + y
x - y
z = x * y
y = y/5
z = z - y^3 + 5*x
% ### Logical operations
mass = 20
age = 2.5
frac = mass/age
c1 = frac < 10
c2 = frac > 10

% ## Data types
% !! Solution:
weight = 64.5
size3 = 'L'
patient_name = "Jane Doe"
alive_on_day_3 = true


c3 = frac == mass/age
c4 = frac < 10 && age > 5
c5 = frac < 10 || age > 5

% ! Challenge:
% ## Negating conditions and including the limits
% !! Solution:


% ### Arrays
A = [1, 2, 3]
B = [1, 2; 3, 4; 5, 6]
Names = ["John", "Abigail", "Bertrand", "Lucile"]
C = [true; false; false; true]
B > 3

% ## Suppressing the output
x = 33;


% ## Printing a variable's value
patient_name
disp(patient_name)


% ## Keeping things tidy
clear alive_on_day_3
clc



65 changes: 65 additions & 0 deletions code/02-arrays.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@




% ## Initializing an Array
Z = zeros(3,5)
Z = zeros(3)
Z = zeros(1x5)
R = rand(8);
O = ones(10,10);


Fives = ones(3,6)*5;
M = magic(4)
% ## Array indexing
M = magic(8)
M(5, 6)


M([4,5,6],[5,6,7])

% ## The `:` operator
1:6
1:3:15

M(4:6, 5:7)

% ! Challenge:
% ## Checkerboard
% !! Solution:
M(1:3:8, 2:2:8)


% ### Selecting whole rows or columns
M(5, 1:8)

% ## The key-word `end`
M(2,end)
M(5:end,3)

M(5, 1:end)

% ## Using `:` as an index
M(5, :)

M(1:4, :)
M(:, 6:end)

% ! Challenge:
% ## Master indexing
% !! Solution:
M(2:3:end, :)



% ! Challenge:
% ## Slicing character arrays
element = 'oxygen';
disp(['first three characters: ', element(1:3)])
disp(['last three characters: ', element(4:6)])
% !! Solution:




72 changes: 72 additions & 0 deletions code/03-loading_data.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@




% ## Loading data to an array

% ## Tip: Good Enough Practices for Scientific Computing

patient_data = readmatrix('data/base/inflammation-01.csv');
size(patient_data)
class(patient_data)
% ## Initial exploration
% #### **One patient at a time**
patient_5 = patient_data(5,:)
mean_p5=mean(patient_5)
max_p5 = max(patient_5)
min_p5 = min(patient_5)
std_p5 = std(patient_5)

% ! Challenge:
% ## All data points at once
% !! Solution:
global_mean = mean(patient_data(:))
global_max = max(patient_data(:))
global_min = min(patient_data(:))
global_std = std(patient_data(:))


mean_p5 > global_mean
max_p5 == global_max
min_p5 == global_min
std_p5 < global_std

% ! Challenge:
% ## Food for thought

% #### **One day at a time**
day_9 = patient_data(:,9);
mean_d9 = mean(day_9)
max_d9 = max(day_9)
min_d9 = min(day_9)
std_d9 = std(day_9)
mean_d9 > global_mean
max_d9 == global_max
min_d9 == global_min
std_d9 < global_std

% ! Challenge:
% ## Food for thought

% #### **Whole array analysis**
x=mean(patient_data);
per_day_mean = mean(patient_data);
per_day_max = max(patient_data);
per_day_min = min(patient_data);
per_day_std = std(patient_data);
per_day_mean > global_mean
find(ans)
help mean
per_patient_mean = mean(patient_data,2);
per_patient_max = max(patient_data,[],2);
per_patient_min = min(patient_data,[],2);
per_patient_std = std(patient_data,[],2);

% ! Challenge:
% ## Most inflamed patients
% !! Solution:
find(per_patient_max == global_max)




81 changes: 81 additions & 0 deletions code/04-plotting.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@




% ## Plotting
plot(1:40,per_day_mean)




title('Daily average inflammation')
xlabel('Day of trial')
ylabel('Inflammation')
plot(per_day_max)
title('Maximum inflammation per day')
ylabel('Inflammation')
xlabel('Day of trial')
plot(per_day_min)
title('Minimum inflammation per day')
ylabel('Inflammation')
xlabel('Day of trial')
% ## Multiple lines in a plot
plot(per_day_mean,DisplayName="Mean")
legend
title('Daily average inflammation')
xlabel('Day of trial')
ylabel('Inflammation')
hold on
plot(patient_5,DisplayName="Patient 5")
hold off

% ! Challenge:
% ## Patients 3 & 4
% !! Solution:
plot(per_day_mean,DisplayName="Mean")
legend
title('Daily average inflammation')
xlabel('Day of trial')
ylabel('Inflammation')
hold on
plot(patient_data(3,:),DisplayName="Patient 3")
plot(patient_data(4,:),DisplayName="Patient 4")
hold off


% ## Multiple plots in a figure
tiledlayout(1, 2)
nexttile
plot(per_day_max)
title('Max')
xlabel('Day of trial')
ylabel('Inflamation')
nexttile
plot(per_day_min)
title('Min')
xlabel('Day of trial')
ylabel('Inflamation')
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)
title('Min')

% ## Clearing a figure

% ## Heatmaps
heatmap(patient_data)
title('Inflammation')
xlabel('Day of trial')
ylabel('Patient number')
imagesc(patient_data)
title('Inflammation')
xlabel('Day of trial')
ylabel('Patient number')


Loading