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?
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!