3-D Polar Plot from mat Data

I am facing a problem in plotting of a data in Polar coordinate. The attached .Mat file “Polar_Data” is the data extracted from a maxwell solver software (Lumerical FDTD) which gives us the same polar plot in FDTD software as hereby shown in the following attached figure. Now I want to plot the same type of image from the extracted data. I tried different commands (polar3, polarplot3d, etc) for plotting of such image but still I didn’t produce the same image in Matlab. It would be so nice of you if use my attached data and help me in writing script to obtain the same image. Thanks in advance.

1 Comment

How do you expect to plot data depending on two independent variables on a 2D plot?
Or does the software provide a 2D view of the surface plotted?

Sign in to comment.

 Accepted Answer

[Edit: added references to the File Exchange programs you referenced.]
I am surprised that you were not satisfied with polar3d or polarplot3d, from the Matlab File Exchange. Those packages look very nice to me. What exactly did you not like about polarplot3d?
farfield is 500x500, r is 1x500, and theta is 1x500. Therefore I cannot tell if the rows or the columns of farfield correspond to R and theta. When I plot the data, it appears that the rows of farfield correspond to different r values, and the columns correspond to different theta values. I recommend that when you have data on a surface, the surface should have different numbers of rows and columns, if possible. If they have the same numbers of rows and columns, you can plot the data incorrectly, or do incorrect calculations, without realizing that you have made an error. (Ask me how I know...) Therefore I eliminated the last row of farfield and the last element of r, and saved the resulting r, theta, and farfield in file Polar_Data1.mat, attached. In my file, farfield is 499x500, r has length 499, theta has length 500.
I do not believe that the data file you provided actually yielded the figure you posted. I say this for the following reasons:
A. The r values in the figure you posted vary from 0 to more than 50 (see radial axis axis labels on your figure), but the r values in the file you sent vary from 0 to 10.
B. The figure you posted has peaks at theta=[0,pi], and at r~=[42,42], but the farfield array has peaks at theta=[pi/3, 5*pi/3], and r=[5.0,5.0].
Here is code that generates two surface plots. The first plot uses r and theta as Cartesian cooridnates. This is not the plot you want. The second plot uses r and theta as polar coordinates. This is more like what you want.
load Polar_Data1
figure;
surf(theta,r,farfield,'EdgeColor','none');
xlabel('$$\Theta$$','Interpreter','latex'); ylabel('R')
view(0,90); colormap jet; colorbar
[Theta,R]=meshgrid(theta,r);
X=R.*cos(Theta); Y=R.*sin(Theta);
figure;
surf(X,Y,farfield,'EdgeColor','none');
axis equal; view(0,90); colormap jet; colorbar
The spacing of the radial gridlines on the figure you posted suggests that the figure is an orthographic projection of a sphere, where the view is from above the north pole, the azimuth corresponds to longitude, and the un-evenly spaced radial values are the co-latitudes (i.e 0 at the pole and +90 at the equator). But the r-values in your file do not vary from 0 to 90. Please clarify.
Good luck.

5 Comments

I downloaded polarplot3d.m, from the file exchange, and added the code below to my script:
polarplot3d(farfield,'RadialRange',max(r),'TickSpacing',15,...
'PolarGrid',[9,24]);
axis equal; view(0,90); colormap jet; colorbar
xlim([-12,12]); ylim([-12,12]);
It produced the plot above.
Thanks for your insightful feedback. Your observations are indeed valuable, and I appreciate the time you've taken to analyze the data and the plots.
Regarding the polar3d/polarplot3d, indeed these packages are well-designed. However, my specific application requires a slightly different approach, especially in terms of data representation and visualization. The standard features of these packages didn't align perfectly with the unique requirements of my desired plot. In my desired plot there is also a third peak at r=0. The location of all the three peaks are at theta=[0, pi/2,pi], and at r~=[42,0,42]. While the locations of all the three PEAKS in the MATLAB polar plot is completely different. Actually, I need exactly the same plot as shown in my uploaded Figure.
We are free to utilize any coordinate system and arbitrary axis data. My desired data is the “farfield” and I need exactly the same plot as uploaded. Please have a look to the given data and it would be really appreciated if try with some other ways to plot such data, whose peaks are on along the same line or located at theta=[0, pi/2,pi], and at r~=[42,0,42].
Once again really appreciated your response and Thanks in advance.
@Naeem,
You wrote
We are free to utilize any coordinate system and arbitrary axis data. My desired data is the “farfield” and I need exactly the same plot as uploaded. Please have a look to the given data and it would be really appreciated if try with some other ways to plot such data, whose peaks are on along the same line or located at theta=[0, pi/2,pi], and at r~=[42,0,42].
The three peaks in the farfield array of your original posting are all on, or close to, the same array row, and the smaller peak is in the middle of the array. Therefore I assume the values of farfield are sampled on a rectangular Cartesian grid. Scale the x vector so the two large peaks are at x=-42,+42. The y vector is identical to the x vector.
Resample farfield onto a polar grid, using interp2(). Plot the resampled farfield with polarplot3d() in order to obtain polar axes and gridlines. The peaks are at the desired locations.
The comments below are from the code.
% The two large peaks in farfield are at row,col=251,84; 251,417.
% The smaller peak is at farfield(249,250).
% Therefore we consider the elements of farfield() to be on a Cartesian
% grid, where x,y=0,0 is at the center (i.e. at i=250.5,j=250.5) and
% dx=dy=84/333.
% We use interp2() to resample farfield onto a polar grid.
% We use polarplot3d() to make Figure 3: a surface plot, with a polar
% grid, of the resampled farfield data.
% Figure 1: surface plot of farfield on Cartesian grid.
% Figure 2: surface plot of farfield, resampled to a polar grid.
% Figure 2 does not have a polar grid on the plot.
% Figure 3: surface plot of resampled farfield, using polarplot3d
% in order to have a polar grid on the plot.
Good luck, Naeem.
Finally you did it and you have successfully implemented. It’s exactly the same what I need it. Thanks for the support and guidance.
@Naeem, you're welcome. Good luck with your work.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 18 Dec 2023

Commented:

on 2 Jan 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!