We all know how to manually convert numbers from Cartesian to Polar and from Polar to Cartesian, Here we will try to get introduced to the Matlab functions that help you quickly convert numbers from Polar to Cartesian form and the vice versa.
Convert from Polar to Cartesian form in Matlab
To convert a number from Polar to Cartesian form in Matlab, you can make use of the pol2cart function. And it goes like this.
Let say we have the following number to convert
Where the radius and the angle are respectively
Here is how you will actually do it with Matlab
[RealPart, ImagPart]=pol2cart(-3*pi/4,4); disp(['Real= ',num2str(RealPart),'; imag= ', num2str(ImagPart)]);
Convert from Cartesian to Polar form
Converting from Cartesian to Polar is a little tricky, since the value of the angle could be misinterpreted.
Let’s convert the following
in Polar form
To do this in Matlab, use the following.
[rad,mag]=cart2pol(2,3); deg=rad*(180/pi); disp(['mag= ',num2str(mag),'; rad= ',num2str(rad),'; deg= ',num2str(deg)]);
Here we converted the result from radiant to degree.
Hope you have learned a few new tricks today. Feel free to drop your concern below if needed.