user309575
user309575

Reputation: 41

Converting matlab polar plot into x,y plot

I have data which produces a polar plot

enter image description here

where I want to obtain the ratio of the x and y data points (x/y) at each angle then plot the ratio (x/y) versus the angle theta (0,...,360). What is the best way to achieve this?

Upvotes: 0

Views: 487

Answers (1)

picchiolu
picchiolu

Reputation: 1129

If you have the rho and theta coordinates for each data point in the plot, you can easily obtain the (x,y) coordinates.

Assuming your polar coordinates are stored in two separate vectors of the same length, 'rho' and 'theta', you could use the following code to extract the respective x and y coordinates:

% theta is expressed in radians
x = rho .* cos(theta) ;
y = rho .* sin(theta) ;

and then compute the ratio as follows:

x_over_y = x ./ y ;

Alternatively, you could do everything in one step, like so:

% theta is expressed in radians
x_over_y = (rho .* cos(theta)) ./ (rho .* sin(theta)) ;

Once you have x_over_y, you can plot it against the theta values:

% theta is expressed in radians
plot(theta*180/pi, x_over_y) ;

Upvotes: 2

Related Questions