Use for loop to compare each row value out of two separate arrays to create a filtered final array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Austin Bollinger
el 18 de Mayo de 2022
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 comentarios
Respuesta aceptada
Voss
el 18 de Mayo de 2022
Editada: Voss
el 18 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!