Conditional statements not catching
古いコメントを表示
I'm trying to check conditions of of pairs of x and y values. Instead of nesting an if statement within another to check x and y, i initially tried to use && feature but kept getting error for "operators must be convertible to logical scalar values". After digging through here, I tried the suggestions to change && to & but logically the code wasn't checking the conditions for each individual x and y scalars in my list.
so now I'm trying to nest my if functions, the code executes but still isn't catching the conditions and triggering what I want it too.
function[theta_r,theta_d] = firstassignment_test(x,y)
theta_r = atan(y./x);
theta_d = theta_r*(180/pi);
if (x>0)
if (y>0)
theta_d = theta_r.*(180/pi);
end
elseif (x<0)
if (y>0)
theta_d = (theta_r+pi).*(180/pi);
end
elseif (x<0)
if (y<0)
theta_d = (theta_r-pi).*(180/pi);
end
elseif (x<0)
if (y==0)
theta_d = pi.*(180./pi);
end
elseif (x==0)
if (y>0)
theta_d = (pi./2)*(180./pi);
end
elseif (x==0)
if (y<0)
theta_d = (-pi./2)*(180./pi);
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!