MATLAB: How can i get the value of the theta i get after transforming it from rectangular to polar, cause i need the theta to convert it again to rectangular

theta

I am new in using MATLAB, I found a way to convert from rectangular to polar using
function [rho,theta] = r2p(x)
[theta, rho] = cart2pol(real(x), imag(x));
fprintf('[%g,%g]\n',theta, rho);
Si = Pli+Qli*1i;
Ii = (r2p(Si)/Vi);
it works but it only print the result it didnt save the value of theta. so i can't transform it back to rectangular again. any clue on how to save the theta data ?
In the program the value of Ii is only the magnitude value no angle or theta.

Best Answer

x = rand + 1i * rand;
% convert from cartesian to polar
[theta, r] = cart2pol (real (x), imag (x));
% the above function is nothing but

ri = abs (x);
thetai = atan (imag (x) / real (x));
% convert from polar to cartesian
[xc, yc] = pol2cart (theta, r);
% the above function is nothing but
xci = r * cos (theta);
yci = r * sin (theta);
Related Question