Matlab if statements in physics

What does the condition mean in Matlab, where x and y are the displacement that measures from [-1,1]
if (abs(x)>=1)
x=sign(x);
end
if (abs(y)>=1)
y=sign(y);
end

2 comentarios

Walter Roberson
Walter Roberson el 18 de Oct. de 2018
The code is checking to see if the values are out of range and if so moving them to the boundary.
Momo
Momo el 19 de Oct. de 2018
you mean x and y will equal 1 or -1 if their values are out of the range? as Mr. James said,right?

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 18 de Oct. de 2018
Editada: James Tursa el 18 de Oct. de 2018
You can easily run the code to see that it clips the values outside of [-1,1] so that they stay in this range. But it appears there is a typo in the y code. This line
x=sign(y);
should probably be this instead (note the y on the lhs)
y = sign(y);

3 comentarios

Momo
Momo el 18 de Oct. de 2018
Editada: Walter Roberson el 19 de Oct. de 2018
what do you mean by "clips the values outside of interval"?
James Tursa
James Tursa el 18 de Oct. de 2018
If x > 1, it will assign x = 1
If x <-1, it will assign x = -1
If x is between -1 and 1, it will leave x unchanged.
Same for y (as long as you fix the typo)
Momo
Momo el 18 de Oct. de 2018
Thank you so much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Elementary Math en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Oct. de 2018

Comentada:

el 19 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by