Function is not working

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 8 Oct 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.

Sign in to comment.

Accepted Answer

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam on 9 Oct 2020
coror = relor + (relor - 180).*(relor > 90) + (relor + 180) .* (relor < -90);
  2 Comments
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam on 9 Oct 2020
Yes, we have some missing:
coror = relor.*(relor>=-90 & relor<=90) + (relor - 180).*(relor>90) + (relor + 180).*(relor<-90);

Sign in to comment.

More Answers (1)

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

Categories

Find more on Live Scripts and Functions in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!