Reputation: 1
I have a set of far-field intensity data (for LED / photonics application) and I am trying to plot them via a polar transformation.
The following is what I have: a 2D array of intensity values, with each row corresponds to a specific phi, which ranges from 0 to 360 at steps of 2; each column corresponds to a specific theta, which ranges from 0 to 90 at steps of 2. This results in a 2D intensity array with dimension of 181 by 46.
If I manually generate the phi and theta values using linspace, I can plot them with the x values being theta, y values being phi, and the intensity would be represented by its color, which I've successfully done already as it's quite straight forward by using pcolor in MATLAB
In order to generate the polar far-field intensity plot however, the x-axis needs to be theta/90*cos(phi), the y-axis needs to be theta/90*sin(phi), with the color representing the intensity once again.
I've created a 3 dimensional array, with size 181x46x3, that stores the calculated x and y, and intensity value for each theta and phi. However I am unable to plot them using pcolor anymore as they are no longer in uniform steps, nor are they sorted in anyway.
Any ideas as to how to plot them?
Thanks in advance.
Upvotes: 0
Views: 110
Reputation: 2323
Depending on what you want to do, you have 2 options, you can scatter your points or you can interpolate them into a grid. For example:
c=peaks(181);
c=c(1:181,1:46);
[th,phi]=meshgrid(0:2:90,0:2:360);
Creates a sample data with a shape similar to what you mention
using pcolor
as
h=pcolor(th,phi,c);
set(h,'edgecolor','none')
You get:
Now you can get the x and y coordinates as:
x=(th./90).*cosd(phi);
y=(th./90).*sind(phi);
First option: Scatter
You can directly plot this as
scatter(x(:),y(:),30,c(:),'fill')
Pros:
Cons :
Second option: Interpolate
You can use griddata
to interpolate these coordinates into a square grid in order to plot it using pcolor
[xv,yv]=meshgrid(-1:0.01:1);
cv=griddata(x,y,c,xv,yv);
h=pcolor(xv,yv,cv);
set(h,'edgecolor','none')
Pros:
Cons :
Upvotes: 0