Info

此问题已关闭。 请重新打开它进行编辑或回答。

Outputting gyroscope data to array

2 次查看(过去 30 天)
Kimberly Savitsky
关闭: MATLAB Answer Bot 2021-8-20
I am trying to plot angles in the z-axis (angz) over time. I have a 1:10 sample rate, so I am able to send 10 samples at a time to an array. However, the code overwrites these 10 samples and sends only the last 10 anglez values to the array (p(n)).
I am trying to adjust the code so I can send all angz values to an array for data analysis.
while abs(angz) < 360
for n = 1:10
q = a.gyroRead('z') - dc_offsetz;
if abs(q) > threshold
dt = toc(timer);
angz = (angz + (q/32768)*sensitivityz*dt - gyro_driftz);
p(n) = angz;
end

回答(1 个)

Joseph Cheng
Joseph Cheng 2017-4-7
编辑:Joseph Cheng 2017-4-7
you're overwriting it with the p(n) as n only goes from 1 to 10 again and again. you'll have to increment p(#) beyond n or multiple of #*(1:10)
collectnum = 0;
while abs(angz) < 360
for n = 1:10
q = a.gyroRead('z') - dc_offsetz;
if abs(q) > threshold
dt = toc(timer);
angz = (angz + (q/32768)*sensitivityz*dt - gyro_driftz);
p(collectnum*10+n) = angz; %so you're increasing the index for every 10 points collected
end %added these end lines to show where you'll need to put the increment of 10 line
end
collectnum=collectnum+1; %need this after the end in your for loop to increment the multiple of 10.
end

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by