简体   繁体   English

在Matlab中绘制加速度计3轴值

[英]Plotting Accelerometer 3 axis value in Matlab

I have two task to do 我有两个任务要做

  1. getting data serially from microcontroller. 从微控制器串行获取数据。
  2. plotting the 3 axis value in real time. 实时绘制3轴值。

For first I used the following code: 首先,我使用以下代码:

s=serial('COM10');
fopen(s);
out=fscanf(s);
while(out~=0)
out=fscanf(s);
disp(out);
end
fclose(s);

now in second part i have to plot there data in real time how can i do it ,m new to matlab i tried the following sample code to plot 3 values but didn't worked out. 现在在第二部分中,我必须实时绘制那里的数据,我该怎么做,这是Matlab的新手,我尝试了以下示例代码来绘制3个值,但没有解决。 please help. 请帮忙。

x = -50;
y = 10;
z = 20;
while(1)

plot3(x,y,z);
XLABEL('X Axis');
YLABEL('Y Axis');
ZLABEL('Z Axis');
set(gca, 'XColor', 'r', 'YColor', [0 0.5 0.5], 'ZColor', 'y')
x=x+2;
y=y+2;
z=z+2;
end

Change the code, use plot only once: 更改代码,仅使用一次绘图:

X=[];Y=[];Z=[];
x=0;y=0;z=0;
figure(1);
myplot=plot3(x,y,z);
while(1)
    x=x+1;
    y=sin(x);
    z=cos(x);
    X(end+1)=x;
    Y(end+1)=y;
    Z(end+1)=z;
    set(myplot,'Xdata',X,'YData',Y,'ZData',Z);
    drawnow limitrate;
end

If the loop run long enough, don't forget to limit X,Y,Z sizes(for example every 1000 samples delete 500) 如果循环运行足够长的时间,请不要忘记限制X,Y,Z的大小(例如,每1000个样本会删除500个)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM