Function is not working
2 次查看(过去 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 个评论
Image Analyst
2020-10-8
Then your coror must be in the range -90 to +90, inclusive. What is gdif and target? What values do they have???
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
2020-10-9
coror = relor + (relor - 180).*(relor > 90) + (relor + 180) .* (relor < -90);
2 个评论
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
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;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Author Block Masks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!