Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Outputting gyroscope data to array

1 回表示 (過去 30 日間)
Kimberly Savitsky
Kimberly Savitsky 2017 年 4 月 7 日
閉鎖済み: 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