How do I plot a contour3 plot from polar cordinates?

I have a dataset such that the first column is the polar angle, second third fourth.... column is the magnitude of the polar coordinate at a different height.
For example, the first row would be all the magnitudes at angle 10 and every column would be the magnitude at a different height. the second row would be at 20 with the magnitude of the field at that angle and so on.
I am fairly new to matlab, but have some idea on how to get basic stuff done. I believe I might be doing something wrong with data array or coordinates. I get a polarplot from the data on excel with all the plots in the same axis, but I would like to get something like a contour3 plot to get an idea for a 3d image. The polar plot I am able to get from matlab is correct with all three layers on same axis (picture attached). I have also attached kinda what my data looks like. Any sort of help is greatly appreciated

 Accepted Answer

I am not certain what your data are. Experiment with the pol2cart function to put your data in Cartesian coordinates (plotted as a polar plot) and then use those transformed data with the contour3 function.

8 Comments

I have attached a sample of kinda what my excel file looks like; I have been tinkering around with using meshgrid for x and y values(having the azimuth angles as my x value, and the magnitudes as my y values), and then using the contour3 function, but it may be that my understanding of how to implement the z value (aka, the height value) with the contour3 is not right.
Please post the file again. There are no data other than the angle. You can attach .csv, .xls, .xlsx and others.
heres a chunk of the file. Thanks a bunch bro
I cannot do much with your data.
See if this does what you want:
[D,S] = xlsread('Uzair Khan matlab.xlsx');
z = bsxfun(@plus, [1:3]*10, D(:,2:end)); % Create ‘z’
[x, y, z] = pol2cart(D(:,1)*pi/180, D(:,2:end), z);
figure(1)
contourf(x, y, z)
axis equal
figure(2)
contour3(x, y, z)
grid on
axis equal
Also, you can attach your Excel files directly here. You do not have to ‘zip’ them first.
I think I have got it using your previous advise aswell, did a little knowledge brushup on axis and stuff. here is the code I used
theta = t.*pi/180; %t is the angle values from the table, found theta values
%rho is also declared as columns 2,3,4
%Declaring z
A = [10 20 30]; %random numbers I used to decide height
z = repmat(A,36,1);
[X,Y,Z] = pol2cart(theta,rho,z); %converting to cartesian
contour3(X,Y,Z); %finally found the contour plot
end
I will give you code a try as well. Btw how we fill the gap between the layers with colors? Again, thanks a lot for your help
My pleasure.
The bsxfun function is more efficient than repmat, although the result will be the same.
If you want to ‘fill’ the space between the contours, use the surf function:
figure(3)
surf(X, Y, Z)
grid on
axis equal
I couldn't thank you enough man, it works perfectly (the code you gave as well). I wish well for your future! :)
As always, my pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!