matlab - How can I convert cartesian coordinates to polar coordinates using function -
i'm trying create function in matlab takes cartesian coordinate , converts polar.
function [homework5] = cartesian(x,y) m = size(x,1) n=1:m if x,y; r=sqrt(x^2+y^2) theta=atan(y/x) else disp('input incorrect') end if r > 10 disp('far origin') else disp('close origin') end end
i'm extremely new matlab , searches answer , reading tutorials e.t.c have proved futile.
i have converts 1 coordinate fine, need convert multiple coordinates @ once (hence forloop) can't it! user needs able enter array this: >>cartesian = [2,3;4,5;6,7] , have each row converted.
thanks help!
don't want use matlab's function cart2pol?
if inside this:
th = atan2(y,x); r = hypot(x,y);
as code, has many issues syntax , logic.
first don't need loop. matlab designed work vectors , matrices. have use element-wise multiplication, delition , power .*
, ./
, .^
operators.
also if x,y;
doesn't anything. read doc how use if
properly. preallocate m
don't use it. function supposed return homework5
, it's not defined in function's body. have read functions. make sure function saved file same name cartesian.m
, in current directory or in matlab's path.
Comments
Post a Comment