Borrar filtros
Borrar filtros

Function is not working

1 visualización (últimos 30 días)
MadjeKoe
MadjeKoe el 8 de Oct. de 2020
Comentada: Asad (Mehrzad) Khoddam el 9 de Oct. de 2020
Can somebody please tell me why this is not working? I'm a beginner with Matlab
relor = gdif(target==2);
if relor > 90
coror = relor - 180;
elseif relor < -90
coror = relor + 180;
else
coror = relor;
end
  4 comentarios
Image Analyst
Image Analyst el 8 de Oct. de 2020
Then your coror must be in the range -90 to +90, inclusive. What is gdif and target? What values do they have???
Walter Roberson
Walter Roberson el 8 de Oct. de 2020
I suspect that target == 2 is true for more than one location, so that relor is a vector instead of a scalar. If so then you need to use logical indexing.

Iniciar sesión para comentar.

Respuesta aceptada

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 9 de Oct. de 2020
coror = relor + (relor - 180).*(relor > 90) + (relor + 180) .* (relor < -90);
  2 comentarios
MadjeKoe
MadjeKoe el 9 de Oct. de 2020
I tried this, but there are still values left outside -90 & 90. How is this possible?
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 9 de Oct. de 2020
Yes, we have some missing:
coror = relor.*(relor>=-90 & relor<=90) + (relor - 180).*(relor>90) + (relor + 180).*(relor<-90);

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 9 de Oct. de 2020
relor = gdif(target==2);
coror = relor;
mask = relor > 90;
coror(mask) = relor(mask) - 180;
mask = relor < -90;
coror(mask) = relor(mask) + 180;

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by