Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Outputting gyroscope data to array

1 vue (au cours des 30 derniers jours)
Kimberly Savitsky
Kimberly Savitsky le 7 Avr 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Joseph Cheng
Joseph Cheng le 7 Avr 2017
Modifié(e) : Joseph Cheng le 7 Avr 2017
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by