How to plot polar with data in matlab like this picture - matlab

I have data representing frequency and decibels, and I want to make a polar like this picture:
What is the command for this?

On MathWorks:
The polar function accepts polar coordinates, plots them in a Cartesian plane, and draws the polar grid on the plane.
polar(theta,rho) creates a polar coordinate plot of the angle theta versus the radius rho. theta is the angle from the x-axis to the radius vector specified in radians; rho is the length of the radius vector specified in dataspace units.
You should be able to get your result with polar(decibels, frequency).

Related

2D fitting lines in 3D plot

I wish to put 2D curve fitting to different axis within a 3D plot. I am attaching an image for reference.
on this actual data set:
As you can see the curve fitting for x and y axis is at z=0 value, I need that at say z=10.
Further, when I try to do curve fitting for x and z data set or y and z data set, the fitted curve instead of appearing on the the X-Z plane or Y-Z plane, is appearing on the X-Y plane.
All help is appreciated.

How do I calculate the area of a projection created by the command "view"?

How do I calculate the area of a projection? For example, using the following code, I get a projection on the X-Z plane.
[x,y,z]=peaks;
surf(x,y,z);
xlabel('x');ylabel('y');zlabel('z')
view([0,0])
X-Z Plane Projection
I want to be able to determine the area of the projection of any surf plot that I create. Is there a command or function for this?
Short answer
polyarea(x(1,:),max(z))+polyarea(x(1,:),min(z))
Explanation
The plot you want to calculate its area is,
In area calculation you need only the borders of the projection,
plot(x(1,:),max(z))
hold on
plot(x(1,:),min(z),'r')
and the output is,
The total area is the summation of both areas (upper border to x axis and lower border to x axis),
>> polyarea(x(1,:),max(z))+polyarea(x(1,:),min(z))
>> 28.5947
If you want to get the projection area at an arbitrary view angle, you can use the viewmtx function to project the surface onto the viewing plane, and then use boundary and polyarea to extract the boundary and calculate the area. Something like this:
% draw your surface
[x,y,z]=peaks;
surf(x,y,z);
xlabel('x');ylabel('y');zlabel('z')
axis equal;
%extract the viewing angle, and calculate the resulting transformation matrix
[az,el]=view(gca);
T= viewmtx(az,el);
% transform the surface points by this transformation matrix
pts= [x(:),y(:),z(:),ones(numel(x),1)]';
tpts= T*pts;
tpts=(tpts(1:3,:))';
% now "tpts" has the surface points projected onto the viewing plane
figure, plot( tpts(:,1), tpts(:,2), 'bo'); axis equal;
% calculate the border of this region, and calculate its area.
border = boundary(tpts(:,1), tpts(:,2));
projectedArea = polyarea(tpts(border,1), tpts(border,2));
This approach is based off of the help for viewmtx.

Gaussian fit on a sphere

I have an array of spatial data [lat,lon,intensity] on the Earth surface. Plotting the data with surf(lon,lat,intensity) shows the surface is a Gaussian shaped. I want to fit a 2D Gaussian function to the data to get the center and spread (mean and variance) of the data.
It's easy to fit a bivariate Gaussian function for data as [x,y,intensity]. But my data is sampled on the sphere. Latitude and longitude cannot be treated as for x and y in cartesian coordinates.

How can I create a slice of a surface plot to create a line? (Matlab)

Given some function z = f(x,y), I'm interested in creating a (1D) line plot along an arbitrary cutting plane in x,y,z. How do I do this in Matlab? Slice, for example, provides a higher dimensional version (colormap of density data) but this is not what I'm looking for.
E.g.:
z = peaks(50);
surf(z);
%->plot z along some defined plane in x,y,z...
This has been asked before, e.g. here, but this is the answer given is for reducing 3D data to 2D data, and there is no obvious answer on googling. Thanks.
If the normal vector of the plane you want to slice your surface will always lay in the xy plane, then you can interpolate the data over your surface along the x,y coordinates that are in the slicing line, for example, let the plane be defined as going from the point (0,15) to the point (50,35)
% Create Data
z=peaks(50);
% Create x,y coordinates of the data
[x,y]=meshgrid(1:50);
% Plot Data and the slicing plane
surf(z);
hold on
patch([0,0,50,50],[15,15,35,35],[10,-10,-10,10],'w','FaceAlpha',0.7);
% Plot an arbitrary origin axis for the slicing plane, this will be relevant later
plot3([0,0],[15,15],[-10,10],'r','linewidth',3);
Since it is a plane, is relatively easy to obtain the x,y coordinates alogn the slicing plane with linspace, I'll get 100 points, and then interpolate those 100 points into the original data.
% Create x and y over the slicing plane
xq=linspace(0,50,100);
yq=linspace(15,35,100);
% Interpolate over the surface
zq=interp2(x,y,z,xq,yq);
Now that we have the values of z, we need against what to plot them against, that's where you need to define an arbitrary origin axis for your splicing plane, I defined mine at (0,15) for convenience sake, then calculate the distance of every x,y pair to this axis, and then we can plot the obtained z against this distance.
dq=sqrt((xq-0).^2 + (yq-15).^2);
plot(dq,zq)
axis([min(dq),max(dq),-10,10]) % to mantain a good perspective

Plotting a rectangular matrix into a circle

I have generated a rectangular matrix with the azimouth angle changing with rows and the radius changing as you change column. These are meant to represent the relative velocities experienced by a rotating helicopter blade. This produces a matrix called Vmat. I want to plot this to appears in a circle (representing the rotation of the blade)
So far I have tried
[R,T] = meshgrid(r,az);
[x,y] = pol2cart(T,R);
surf(x,y,Vmat(r,az));
which should produce a contoured surface showing velocity as it changes with azimouth angle and radius but it comes up with dimension errors.
I don't mind if it is a 2d contour plot or 3d plot i guess both would be written in a similar way.
Thanks
James
The error is in writing Vmat(r,az), presuming that these are actual values of radius and azimuth, not indexes into your radius and azimuth. If you want to take only a subset of Vmat that's a slightly different matter, but this should work:
[R,T] = meshgrid(r,az); % creates a grid in polar coordinates
[x,y] = pol2cart(T,R); % changes those to cartesian for surf
surf(x,y,Vmat);
Alternatively you could do a contour plot:
h = polar([0 2*pi], [0 max(r)]); % set up polar axes with right scale
delete(h) % remove line
hold on
contour(x,y,Vmat);