MATLAB动画显示串口数据【实例】
2013-01-04 02:32
483 查看
MATLAB动画显示串口数据【实例】
经过几天的学习,现在能实现串口数据的实时plot并记录在MATLAB变量中。
After a few days' learning, we can implement that
real-time plot the data from serial port.
先看一下演示的视频吧:(see demo video)
http://v.youku.com/v_show/id_XNDk2OTA1OTQw.html
升级版(双数据接收,绘图):http://v.youku.com/v_show/id_XNDk3NzM0NzE2.html
The outline of the video:
演示视频大纲:
1.介绍系统构成
2.介绍板载C语言程序
3.用Linux界面演示由MATLAB发送给目标板的命令,及理论返回值。
4.介绍MATLAB本实例的m文件的主要功能,发送的命令,判断,画图
5.演示整个MATLAB程序的实现效果
完成这个实例需要学习“MATLAB串口操作官方教程.pdf” 和 "Matlab中使用Plot函数动态画图方法总结",
请点击。
To finish this subject, we need firstly learn"Official tutorial for MATLAB serial port operation "
板卡产生数据源程序(C语言): The source code for generating original data on the TLL main board.
--------------------
--------------------------------------------
MATLAB 接收数据主程序serial-test.m:
The main program for receiving data in MATLAB:
--------------------------------------------
MATLAB 接收数据,判断,动态绘图,回调函数 callback.m:
The Callback function for receiving, judge, plotting in MATLAB.
Explore more: Real-time plotting in MATLAB for the Three axis accelerometer data
三轴力传感器数据在MATLAB中实时绘图显示:
/article/1460229.html
--------------------------------------------
经过几天的学习,现在能实现串口数据的实时plot并记录在MATLAB变量中。
After a few days' learning, we can implement that
real-time plot the data from serial port.
先看一下演示的视频吧:(see demo video)
http://v.youku.com/v_show/id_XNDk2OTA1OTQw.html
升级版(双数据接收,绘图):http://v.youku.com/v_show/id_XNDk3NzM0NzE2.html
The outline of the video:
演示视频大纲:
1.介绍系统构成
2.介绍板载C语言程序
3.用Linux界面演示由MATLAB发送给目标板的命令,及理论返回值。
4.介绍MATLAB本实例的m文件的主要功能,发送的命令,判断,画图
5.演示整个MATLAB程序的实现效果
完成这个实例需要学习“MATLAB串口操作官方教程.pdf” 和 "Matlab中使用Plot函数动态画图方法总结",
请点击。
To finish this subject, we need firstly learn"Official tutorial for MATLAB serial port operation "
板卡产生数据源程序(C语言): The source code for generating original data on the TLL main board.
--------------------
#include"stdio.h" #include"math.h" #include"string.h" #define pi 3.1415926 void delay(int a){ int i,j,delay; for(i = 0 ; i < 1000*a; i++){ delay = 0; for(j = 0; j < 1000*a; j++){ delay = delay+1; } } } int main(){ float angle, x, y,rad; int i,N,dltime; angle = 0; //getchar(); printf("input the num of circles, delay time: "); scanf("%d,%d", &N, &dltime); for (i = 0; i < 100*N ; i++){ angle = angle + 3.6; rad = angle/180*pi; x = cos(rad); y = sin(rad); printf("%f \n", x); delay(dltime); } return 0; }
--------------------------------------------
MATLAB 接收数据主程序serial-test.m:
The main program for receiving data in MATLAB:
clc; %% % Use EraseMode,draw dynamically. Change axis dynamically. % Multi-Line drawing line global i; global t; global x; global m; t = [0]; % initialize m = [0]; % initialize i = 0; x = -pi ; p = plot(t,m,... 'EraseMode','background','MarkerSize',5); axis([x x+2*pi -1.5 1.5]); % x = [-1.5 pi, 0.5 pi] grid on; %% s = serial('COM3'); % creat serial port obj set(s,'BaudRate',115200,'DataBits',8,'StopBits',1,... 'Parity','none','FlowControl','none'); % set properties for serial s.BytesAvailableFcnMode = 'terminator'; % byte number or terminator s.BytesAvailableFcn = {@callback,p}; % {@mycallback,time} fopen(s); fprintf(s,'cd /home'); pause(1); % pause function, 1s fprintf(s,'./matlab-serial'); pause; % pause function fprintf(s,'1,1'); pause; %right here is receiving the data and plot fclose(s); delete(s) clear s close all; clear all;
--------------------------------------------
MATLAB 接收数据,判断,动态绘图,回调函数 callback.m:
The Callback function for receiving, judge, plotting in MATLAB.
function callback(s,BytesAvailable,p) global i; global t; global x; global m; % p = plot(t,m,... % 'EraseMode','background','MarkerSize',5); out = fscanf(s) %read data from s data = str2num(out); if data>-2 & data < 2 %detect if data is legal % disp('*******data comes! \n'); t=[t 0.01*2*pi*i]; %0 0.1 0.2 0.3.. %Matrix 1*(i+1), column is increasing m=[m data]; %Matrix 2*(i+1), 2row, i+1 column. %set(p(1),'XData',t,'YData',m(1,:)) %set(p(2),'XData',t,'YData',m(2,:)) set(p,'XData',t,'YData',m(1,:)) drawnow x = x + 3.6/360*2*pi; % x = x+0.1 axis([x x+2*pi -1.5 1.5]); pause(0.1); i = i+1; end end
Explore more: Real-time plotting in MATLAB for the Three axis accelerometer data
三轴力传感器数据在MATLAB中实时绘图显示:
/article/1460229.html
--------------------------------------------
相关文章推荐
- matlab 坐标图动画,动态显示数据
- 用matlab实时读取串口数据并动态显示曲线
- matlab读取串口数据并显示曲线
- MATLAB利用串口接收数据,并实时显示图形
- 解决了java+matlab混编+web(jsp)调用Matlab,网页中显示Figure,详细实例
- 如何清空串口接收数据显示框(EDIT控件)的数据
- LCD1602显示单片机与PC机间串口收发数据
- Matlab 串口 数据滤波
- LE一个通过java串口通信控制LED显示数据的实例
- C#SerialPort如何读取串口数据并显示在TextBox上
- 上位机接收到串口发来的数据,实时的以曲线显示的软件开发
- matlab中数据类型及图像显示
- ArcGIS Engine + C# 实例开发教程:第八讲 属性数据表的查询显示
- Flutter学习之旅(五)----网络请求获取数据、解析数据和显示等待动画
- AWS EC2 复制实例后,自定义指标无法显示数据
- IOS第七天(4:UiTableView 数据的显示优化重复实例和tableFooterView和tableHeaderView)
- C# ---- 串口数据 YSI 实例(续)
- java中对list分页并显示数据到页面实例代码
- fmri的图像数据在matlab中显示,利用imagesc工具进行显示,自带数据集-by 西南大学xulei教授
- SerialPort如何读取串口数据并显示在TextBox上,多线程委托