Use for loop to compare each row value out of two separate arrays to create a filtered final array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to compare and filter two seperate arrays to make a final filtered array that will display a tilt perception in angles. I am trying to run it through a for loop to compare each row and spit out the final value. I was able to make it work with just two values Pitch 17.99 Roll 9.073 which spits out an angle of 25.88 but I want it to read all the row values in the arrays and give a number. Any help would be appreciated, I am stuck at this moment what to fix.
RollValue = CorrJoystickRoll1(:,1);
PitchValue = CorrJoystickPitch1(:,1);
Angle =[];
for i = 1:length(PitchValue)
if (RollValue>0)&(PitchValue>0)
Angle = atand((sind(RollValue))/tand(PitchValue));
elseif (RollValue>0)&(PitchValue<0)
Angle = 90 - atand((sind(RollValue))/tand(PitchValue));
elseif (RollValue<0)&(PitchValue<0)
Angle = 180 + atand((sind(RollValue))/tand(PitchValue));
elseif (RollValue<0)&(PitchValue>0)
Angle = 270 - atand((sind(RollValue))/tand(PitchValue));
elseif (RollValue>0)&(PitchValue==0)
Angle = 90;
elseif (RollValue<0)&(PitchValue==0)
Angle = 270;
elseif (RollValue==0)&(PitchValue>0)
Angle = 0;
elseif (RollValue==0)&(PitchValue<0)
Angle = 180;
end
Angle;
end
0 commentaires
Réponse acceptée
Voss
le 18 Mai 2022
Modifié(e) : Voss
le 18 Mai 2022
Inside the for loop, use RollValue(i) and PitchValue(i) instead of RollValue and PitchValue, and also you'll need to assign to Angle(i) instead of Angle each time.
However, you can do the same operations more efficiently using logical indexing rather than a for loop:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!