Function is not working

조회 수: 1(최근 30일)
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
Walter Roberson
Walter Roberson 2020년 10월 8일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Asad (Mehrzad)  Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 9일
coror = relor + (relor - 180).*(relor > 90) + (relor + 180) .* (relor < -90);
  댓글 수: 2
Asad (Mehrzad)  Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 9일
Yes, we have some missing:
coror = relor.*(relor>=-90 & relor<=90) + (relor - 180).*(relor>90) + (relor + 180).*(relor<-90);

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Walter Roberson
Walter Roberson 2020년 10월 9일
relor = gdif(target==2);
coror = relor;
mask = relor > 90;
coror(mask) = relor(mask) - 180;
mask = relor < -90;
coror(mask) = relor(mask) + 180;

태그

Community Treasure Hunt

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

Start Hunting!

Translated by