MATLAB: 循环loop、脚本-文件和绘图、函数-文件(M-文件)、信号生成和卷积、傅里叶变换、滤波器filter的实现

引言

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:)

2dcce78cfd8f4f338b42fe19d10d7039.png

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.)

 

3bb018cd04c14904a35c59479348bbae.png
4fa6073dd2ec479e979d4a5bf74c322b.png           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;

 

dd16a1c418ba4e9e87d0c77ab5f278ca.png

                                     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.)

f58e83260ba74cb7b10c9223069be379.png

d8b7756139a54df1a498889dd0b79ede.pngFigure 2

 

Task 2 Result Code:

x_values = 0:1:480;
y = zeros(size(x_values));

pattern_length = 240;
for i = 1:leng

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值