matlab读取串口数据并显示曲线的实现示例
作者:蓝白的天空 时间:2022-12-17 15:56:17
matlab程序读取单片机通过串口传来的IMU角度数据,并用曲线显示出来。
上传的值为float型,每个数据后有回车符。范围90~-90
主文件 serial_test2.m
%%
clc;
global t;
global x;
global m;
global ii;
t = [0];
m = [0];
ii = 0;
x = -100;
p = plot(t,m,'EraseMode','background','MarkerSize',5);
axis([x-200 x+200 -90 90]);
grid on;
%%
try
s=serial('com4');
catch
error('cant serial');
end
set(s,'BaudRate', 115200,'DataBits',8,'StopBits',1,'Parity','none','FlowControl','none');
s.BytesAvailableFcnMode = 'terminator';
s.BytesAvailableFcn = {@callback,p};
fopen(s);
pause;
fclose(s);
delete(s);
clear s
close all;
clear all;
回调函数 callback.m
%%
function callback(s, BytesAvailable,p)
global t;
global x;
global m;
global ii;
out = fscanf(s);
data = str2num(out)
t = [t ii];
m = [m data];
set(p, 'XData',t,'YData',m(1,:));
drawnow
x = x + 1;
axis([x-200 x+200 -90 90]);
ii=ii+1;
end
来源:https://blog.csdn.net/qwertyuj/article/details/12108155
标签:matlab,串口,曲线
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一篇文章带你详细了解python中一些好用的库
2022-03-18 09:02:19
![](https://img.aspxhome.com/file/2023/4/99044_0s.jpg)
70+漂亮且极具亲和力的导航菜单设计推荐[译]
2009-02-23 13:15:00
![](https://img.aspxhome.com/file/UploadPic/up/2009022313285860.gif)
opencv与numpy的图像基本操作
2022-06-20 12:20:10
![](https://img.aspxhome.com/file/2023/4/102774_0s.jpg)
python高阶函数functools模块的具体使用
2022-12-08 09:03:15
chatGPT本地部署、运行和接口调用的详细步骤
2023-08-31 03:46:31
![](https://img.aspxhome.com/file/2023/9/104959_0s.jpg)
Python3如何在服务器打印资产信息
2023-11-15 08:03:45
![](https://img.aspxhome.com/file/2023/5/63545_0s.png)
python 读取txt,json和hdf5文件的实例
2022-02-18 10:43:34
Asp与JS的数组和字符串下标介绍
2022-10-11 13:40:25
IE8网页显示不正常 用”兼容性视图”搞定
2009-03-28 11:13:00
![](https://img.aspxhome.com/file/UploadPic/20093/28/u2973p2t78d16163f3306dt20090319092333-31s.png)
Mootools 1.2教程(13)——正则表达式
2008-12-07 20:25:00
交互设计师心得——核心竞争力
2010-01-19 13:45:00
![](https://img.aspxhome.com/file/UploadPic/20101/19/126eb492886g215-16s.jpg)
Python Mysql自动备份脚本
2024-01-16 00:57:46
Python3.7+tkinter实现查询界面功能
2023-05-16 18:24:54
![](https://img.aspxhome.com/file/2023/9/98869_0s.png)
Python descriptor(描述符)的实现
2021-12-22 09:07:56
![](https://img.aspxhome.com/file/2023/0/90400_0s.png)
DBA应当了解的MySQL客户端程序启动选项
2009-01-04 13:00:00
![](https://img.aspxhome.com/file/UploadPic/20091/20091511658825.jpg)
Pycharm最新激活码2019(推荐)
2023-07-24 20:30:26
![](https://img.aspxhome.com/file/2023/1/89221_0s.jpg)
Python爬虫入门案例之回车桌面壁纸网美女图片采集
2022-12-25 19:40:57
![](https://img.aspxhome.com/file/2023/9/133649_0s.png)
VS2019如何查看类图的方法实现
2023-08-22 04:12:01
![](https://img.aspxhome.com/file/2023/2/132462_0s.png)
mysql 数据同步 出现Slave_IO_Running:No问题的解决方法小结
2024-01-22 22:59:34
浅析JavaScript中的隐式类型转换
2024-04-29 13:38:22