Good evening, cause I'm in South Korea now is evening.
I wanna ask about M-file functions with input values in command window.
I thought it goes well, but it still doesn't work.
function ST1_5_3(x,y)
r = sqrt(x.^2 + y.^2);
n = length(x);
theta = size(n);
fprintf(' x y r theta \n');
for i = 1:n
if x(i) > 0
theta(i) = atan(y(i) / x(i));
elseif x(i) < 0
if y(i) > 0
theta(i) = atan(y(i) / x(i)) + pi;
elseif y(i) < 0
theta(i) = atan(y(i) / x(i)) - pi;
else
theta(i) = pi;
end
elseif y(i) > 0
theta(i) = pi / 2;
elseif y(i) < 0
theta(i) = -pi / 2;
else
theta(i) = 0;
end
end
theta(i) = th(i) * 180 / pi;
end
fprintf('%2d %2d %5.2f %5.2f\n', x(i), y(i), r(i), theta(i));
end
[Command Window] x = [2 2 0 -3 -2 -1 0 0 2]; y = [0 1 3 1 0 -2 0 -2 0 2]; ST1_5_3(x,y)
And the error message is 'Matrix dimensions must agree.
and error in ST1_5_3 r=sqrt(x.^2+y.^2); '
How can I solve it...?

댓글 수: 2

Steven Lord
Steven Lord 2018년 9월 26일
What size is the x vector that you're passing into ST1_5_3?
What size is the y vector that you're passing into ST1_5_3?
Since x.^2 and y.^2 are the same sizes as x and y respectively, can you add x.^2 and y.^2?
Ho Lee
Ho Lee 2018년 9월 26일
Thanx for comment... I'm such an idiot... that I didn't recognize the difference of size x vector and y vector... I wish you have a wonderful day!

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

 채택된 답변

Guillaume
Guillaume 2018년 9월 26일

0 개 추천

How can I solve it...?
Provide a x and y input that are the same size

댓글 수: 1

Ho Lee
Ho Lee 2018년 9월 26일
Thanx for your comment. I am such an idiot... that I didn't recognize the difference between the size of x vector and y vector.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

질문:

2018년 9월 26일

댓글:

2018년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by