if elseif end error

4 ビュー (過去 30 日間)
Sungmin Na
Sungmin Na 2018 年 4 月 1 日
回答済み: Manan Mishra 2018 年 4 月 4 日
hi i got some error during use matlab
function [r,theta] = matlab36
x = [2 2 0 -3 -2 -1 0 0 2];
y = [0 1 3 1 0 -2 0 -2 2];
r = sqrt((x.^2)+(y.^2));
if x>0
theta = atan(y./x);
end
if x<0
if y>0
theta = atan(y./x)+pi;
elseif y<0
theta = atan(y./x)-pi;
elseif y==0
theta = pi;
end
end
if x==0
if y>0
theta = pi/2;
elseif y<0
theta = -pi/2;
elseif y==0
theta = 0;
end
end
the answer says there is no any substitution value 'theta' i don't know how can i fix this error

回答 (1 件)

Manan Mishra
Manan Mishra 2018 年 4 月 4 日
I was not able to reproduce the same error on my end. However the issue could be because the output theta is not being assigned during the function call.
This is because none of the if-statements under which theta is assigned are being executed.
Please note that for a vector x, the condition x>0 will return true only if all the elements of x are greater than 0.

カテゴリ

Help Center および File Exchange연산자와 기초 연산 についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!