- x,y,z components of acceleration are in a 3-vector returned from the readAcceleration routine,
- can return the sample time for each reading in some manner into variable t which is needed for an abscissa plotting location by addpoints
How can I change this code to get the line when plotting the graph? Because I tried adding commands related but still there is no line when I am running the codes
1 次查看(过去 30 天)
显示 更早的评论
function [] = i2c_sensor()
a = arduino('COM3', 'UNO');
imu = mpu6050(a,'SampleRate',50,'SamplesPerRead',10,'ReadMode','Latest');
for i=1:10
accelReadings(i,:) = readAcceleration(imu);
display(accelReadings(i,:));
pause(1);
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration values from mpu6050');
x_val = animatedline('Color','r');
y_val = animatedline('Color','g');
z_val = animatedline('Color','b');
end
end
0 个评论
采纳的回答
dpb
2021-2-2
You're creating a new animatedline object every time, not adding points to the ones intended...that's not how the examples in the documentation show using it.
function [] = i2c_sensor()
a = arduino('COM3', 'UNO');
imu = mpu6050(a,'SampleRate',50,'SamplesPerRead',10,'ReadMode','Latest');
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration values from mpu6050');
hx_val = animatedline('Color','r');
hy_val = animatedline('Color','g');
hz_val = animatedline('Color','b');
for i=1:10
accelReadings(i,:) = readAcceleration(imu);
t(i)=????
display(accelReadings(i,:));
addpoints(hx_val(t(i),accelReadings(i,1));
addpoints(hy_val(t(i),accelReadings(i,2));
addpoints(hz_val(t(i),accelReadings(i,3));
drawnow
pause(1);
end
end
ASSUMPTIONS:
Read the documentation for both animatedline and addpoints and look at all the examples carefully for further enhancements in using.
3 个评论
Walter Roberson
2021-2-3
addpoints(hx_val, t(i),accelReadings(i,1));
addpoints(hy_val, t(i),accelReadings(i,2));
addpoints(hz_val, t(i),accelReadings(i,3));
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!