how to plot 3 different lines in single 3 d plot?

1 次查看(过去 30 天)
i have accelerometer which gives 3 axis values.i read the data from accelerometer and plotting a graph. i succeeded in plotting only 1-axes value and the code is as shown below
[gx,gy,gz] = readAcc(accelerometer);
gxdata=[gxdata(2:end); gx];
plot(index,gxdata,'r');
axis([1 buf_len -3.5 3.5]);
i want to plot all gx,gy,gz values in a single 3D plot with different color lines.how to do that?

采纳的回答

Walter Roberson
Walter Roberson 2016-1-30
If you have R2014b or later, I suggest you create some animatedLine with your desired maximum length, and addpoint() the data as it comes in.
If you are not trying to limit the length of the lines then I would suggest:
gdata = []; %initialize
for index = 1 : inf
[gx, gy, gz] = readAcc(accelerometer);
gdata = [gdata; gx, gy, gz];
plot(1:index, gdata);
drawnow();
end
Except that more efficient would be:
gdata = []; %initialize
hx = line(nan, nan, 'color', 'r'); %do not use [] to initialize them
hy = line(nan, nan, 'color', 'g');
hz = line(nan, nan, 'color', 'b');
for index = 1 : inf
[gx, gy, gz] = readAcc(accelerometer);
gdata = [gdata; index, gx, gy, gz];
set(hx, 'XData', gdata(:,1), 'YData', gdata(:,2));
set(hy, 'XData', gdata(:,1), 'YData', gdata(:,3));
set(hz, 'XData', gdata(:,1), 'YData', gdata(:,4));
drawnow();
end
  1 个评论
Gowrishankar R
Gowrishankar R 2016-2-1
can you suggest any tutorial/website where can i learn to draw real time 3D visualization of accelerometer using Matlab? what i am doing is i want to place accelerometer on the hand and i want to visualize the movement of the hand in real time?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by