Convert Cartesian to Polar using custom functions

조회 수: 6 (최근 30일)
Ashton Thorsen
Ashton Thorsen 2013년 4월 3일
Hello! I'm having trouble figuring out how to convert cartesian to polar using only custom functions. I'm extremely new to MATLAB and I haven't been able to find a turotial or help guide online that I can make sense of.
Basically, the user needs to be able to submit an array full of however many points they want, the function then takes that array and converts each point into polar coordinates.
So far I have this:
function [homework5] = Cartesian(X,Y)
M = size(X,1)
for N = M;
if X,Y;
r=sqrt(X^2+Y^2)
theta=atan(Y/X)
else
disp('input incorrect')
end
if r > 10
disp('Far from Origin')
else
disp('Close to Origin')
end
end
It converts one pair just fine but when more than one is entered it doesn't work. I know it's a problem with my for loop and M variable but I just don't know what.
  댓글 수: 4
Mahdi
Mahdi 2013년 4월 3일
I also suggest using 'dot' operators when multiplying and squaring, because you want it to be scalar multiplication, and not matrix multiplication. For example, use
r=sqrt(X.^2+Y.^2)
theta=atan(Y./X)
Ashton Thorsen
Ashton Thorsen 2013년 4월 3일
My intention was to say "if X and Y are submitted then do this" Which I think I'm channeling to much pHp logic into this! I want the for loop to know to run it however many points there are.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by