Smallest change for a please

Hi, I have a data for angle in degrees: deg=[10 10 270], and would like to calculate smallest change ie ans=(0 0 80)

2 comentarios

Walter Roberson
Walter Roberson el 10 de Oct. de 2015
Smallest change in angle between what and what?
Aswas
Aswas el 11 de Oct. de 2015
Editada: Aswas el 11 de Oct. de 2015
10, 10 and 270 are true degrees (ie direction of a pointer), so at 1st min was pointing 10deg, 2nd min pointing 10deg, 3rd min pointing 270deg. I'd like my answer to display 0deg for first min, 0deg for second minute (diff btw 10 and 10) and 80deg (diff btw 10 and 270 deg)for 3rd min(not 260 degrees)

Iniciar sesión para comentar.

 Respuesta aceptada

Guillaume
Guillaume el 11 de Oct. de 2015

0 votos

angles = [10 10 270];
changes = mod(diff(angle), 180)

Más respuestas (1)

Walter Roberson
Walter Roberson el 11 de Oct. de 2015

1 voto

80 degrees is not the difference between 10 and 270. 100 degrees is the difference between 10 and 270. You have to pass down through the 10 to 0 degrees and then travel another 90 degrees to reach -90 degrees = 270 degrees, and that is a total of 100 degrees.

4 comentarios

Aswas
Aswas el 11 de Oct. de 2015
Thanks Walter, so how can I get [ 0 100] for my answer please?
Walter Roberson
Walter Roberson el 11 de Oct. de 2015
Editada: Walter Roberson el 11 de Oct. de 2015
deg = [10 10 270];
t = abs(diff([0 deg]));
result = min(t, 360-t)
Walter Roberson
Walter Roberson el 11 de Oct. de 2015
I had added the 0 because initially you wanted 3 outputs for 3 inputs.
Aswas
Aswas el 12 de Oct. de 2015
Thanks again.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 10 de Oct. de 2015

Editada:

el 12 de Oct. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by