引言
MATLAB软件具备多种功能,在数据分析方面,它可以对数据进行探查、建模和可视化;在创建图形方面,MATLAB可以通过图形可视化并探查数据;在编程方面,MATLAB可以进行编程创建脚本、函数和类。同时,MATLAB可以与多种编程语言使用,例如可以将 MATLAB 与 Python、C/C++、Fortran、Java 及其他语言结合使用;在App 构建方面,MATLAB可以创建桌面 App 和 Web App;在硬件方面,MATLAB可以连接到硬件;在并行计算方面,MATLAB使用多核台式机、GPU、集群、网格和云来进行大规模计算...
1.0 Loops循环
1)通过单击文件→新建→空白M-文件打开新脚本。(Open a new script by clicking File → New → Blank M-File.)
2)设置MATLAB的路径以运行文件(文件→设置路径)。添加你所在的文件夹
通过单击添加文件夹按钮保存了文件。选择文件夹,然后单击
按钮保存→关闭。
(Set the path to MATLAB to run the file (File → Set Path). Add the folder in which you
have saved the file by clicking the button Add Folder. Choose the folder and click the
button Save → Close.)
3) 将以下代码添加到M-File中:
(Add the following codes to the M-File:)
4) 保存文件。(文件→另存为)(Save the file. (File → Save As)
5)通过单击调试→运行filename.m运行M-File。(Run the M-File by clicking Debug → Run filename.m.)
6) 保存数字。(Save the figures.)
7) 将绘图命令更改为茎和楼梯,然后运行文件。(Change the plot command to stem and stairs and run the file.)
Alright,Let's do some tasks now😊
Task 1:
使用下面的公式创建葡萄糖摄入量(𝐺𝑛)图。复制该方程并进行一些修改,生成如图1所示的图。
(Use the equation below to create Glucose intake (𝐺𝑖𝑛) graph. Duplicate the equation with some modification to produce the graph as in Figure 1.)
Figure 1
Task 1 Results Code:
% Define the time intervals t = linspace(0, 400, 4000);
% Initialize Gin
Gin = zeros(size(t));
% Loop over the time intervals
for i = 1:length(t)
if t(i) >= 0 && t(i) < 17.5
Gin(i) = 0.25 + (4.75/17.5)*t(i); % Increasing part of the first spike
else if t(i) >= 17.5 && t(i) < 35
Gin(i) = 5 - (4.75/17.5)*(t(i)-17.5); % Decreasing part of the first spike
else if t(i) >= 35 && t(i) < 240
Gin(i) = 0.25; % Constant part between the spikes
else if t(i) >= 240 && t(i) < 257.5
Gin(i) = 0.25 + (4.75/17.5)*(t(i)-240); % Increasing part of the second spike
else if t(i) >= 257.5 && t(i) < 275
Gin(i) = 5 - (4.75/17.5)*(t(i)-257.5); % Decreasing part of the second spike
else
Gin(i) = 0.25; % Constant part after the second spike
end
end
% Plot the graph
figure(1);
plot(t, Gin);
title('Glucose Intake Rate');
xlabel('Time (t)');
ylabel('Gin(t)');
grid on;
Task 1 Result
Task 2:
使用下面的公式创建一个Lispro胰岛素摄入量(𝐼𝑛)图。复制该方程并进行一些修改,生成如图2所示的图。
(Use the equation below to create a Lispro insulin intake (𝐼𝑖𝑛) graph. Duplicate the equation with some modification to produce the graph as in Figure 2.)
Figure 2
Task 2 Result Code:
x_values = 0:1:480;
y = zeros(size(x_values));
pattern_length = 240;
for i = 1:leng