【问题标题】:Plotting Accelerometer 3 axis value in Matlab在 Matlab 中绘制加速度计 3 轴值
【发布时间】:2018-01-06 13:45:25
【问题描述】:

我有两个任务要做

  1. 从微控制器串行获取数据。
  2. 实时绘制 3 轴值。

首先我使用了以下代码:

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

现在在第二部分中,我必须实时绘制数据我该怎么做,我是 matlab 的新手,我尝试了以下示例代码来绘制 3 个值,但没有成功。请帮忙。

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

【问题讨论】:

  • 您发布的解决方案有什么问题?请在文本中使用大写字母。
  • @Bernhard 该图没有显示任何线条,因为我的想法是在无限循环中绘制 3 个值。所以当我连续获取 uart 上的 3 轴值时,我可以实现相同的值。这是正确的方法吗?

标签: matlab plot serial-communication


【解决方案1】:

更改代码,仅使用一次绘图:

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

如果循环运行时间足够长,不要忘记限制 X、Y、Z 大小(例如每 1000 个样本删除 500 个)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 2017-10-09
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 2011-03-23
    相关资源
    最近更新 更多