How can I get 3D continuous plot of real time data ?

조회 수: 8 (최근 30일)
Aradhya Anil Tare
Aradhya Anil Tare 2020년 1월 8일
댓글: Aradhya Anil Tare 2020년 1월 11일
Hey, I'm working on MPU 9250. I want to plot real time data of MPU in 3D, I'm able to plot real data in 3D, the plot contained all the data from first reading to the last but I want to plot the first reading then the second reading and so on. I'm not able to plot the data. Please help me.
Thank you in advance.
Regards,
Aradhya Tare
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 1월 8일
Aradhya - how are you plotting the data from the first reading? How do you then plot data from the second reading? Please include a sample of your code. And is the "first reading" a single point or is it multiple points?
Aradhya Anil Tare
Aradhya Anil Tare 2020년 1월 9일
편집: Geoff Hayes 2020년 1월 10일
%%for reading the data the data is already stored in the folder
accel_tab = readtable('angular_acceleration.xlsx') ;
gyro_tab = readtable('angular_velocity.xlsx') ;
mag_tab = readtable('magnetic_field.xlsx') ;
%% Conversion from table to array
accel = table2array(accel_tab);
gyro = table2array(gyro_tab);
mag = table2array(mag_tab);
%% for plotting
%x-accel contains all the x coordinates of acceleration
for i = 1:1000-1
plot3( x_accel(i), y_accel(i), z_accel(i))
end
is the code is right ?

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 1월 10일
편집: Geoff Hayes 2020년 1월 10일
Aradhya - everytime you call plot3 you are creating a new plot (graphics) object and the previous one is deleted. Perhaps that is why you are not seeing all of the data being plotted (if I understand your question correctly). Rather than using a loop to plot the data, just do it all at once
plot3( x_accel(1:999), y_accel(1:999), z_accel(1:999))
Else if you want to plot each point (with perhaps a pause between each one), then you will want to create one plot object and update that on each iteration of your loop
hPlot = plot3(x_accel(1), y_accel(1), z_accel(1));
for k = 2:1000-1
pause(0.5);
xdata = [get(hPlot, 'XData') ; x_accel(k)];
ydata = [get(hPlot, 'YData') ; y_accel(k)];
zdata = [get(hPlot, 'ZData') ; z_accel(k)];
set(hPlot, 'XData', xdata, 'YData', ydata, 'ZData', zdata);
end
I haven't tested the above, but it should work something like that.
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2020년 1월 11일
Sorry, Aradhya. Try removing the semi-colons:
hPlot = plot3(x_accel(1), y_accel(1), z_accel(1));
for k = 2:1000-1
pause(0.5);
xdata = [get(hPlot, 'XData') x_accel(k)];
ydata = [get(hPlot, 'YData') y_accel(k)];
zdata = [get(hPlot, 'ZData') z_accel(k)];
set(hPlot, 'XData', xdata, 'YData', ydata, 'ZData', zdata);
end
Aradhya Anil Tare
Aradhya Anil Tare 2020년 1월 11일
It Worked, thank you so much. :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Selva Karna
Selva Karna 2020년 1월 9일
plot3d(x,y,z,'-or');

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by