scatter polar plot interpolation

How can I produce a scatter plot in polar coordinates in Matlab? I need to have a scatter plot (r,theta,Z) where Z values are represented with a colorbar.
The result which I would like to obtain is the same of polarPlot function in R (openair package). In the image you can see an example of graph obtained
with R.
R_WDS_NO3_emission.png
In Matlab I tried with ScatterWindRose (from File Exchange) function, but it is not exactly what I want. I need a kind of surface interpolation of the dots.
screenshot scatter plot.jpg
Can you help me?

 Accepted Answer

Have a look at the help for TriScatteredInterp, griddata those functions should help you interpolate between your measurement points, then you might have use for this file exchange contribution: Polar pcolor
HTH

4 Comments

I tried to use polarPcolor function from File Exchange. This is the code used:
[h,c]=polarPcolor(mediau,tetanord,media_a1*media_a1');
where media_a1 is a daily mean of concentration (1x42384), mediau is the average wind velocity (1x42384) and tetanord id the wind direction (1x42384)
in this case I have a memory issue. This is the warning:
"Requested 42384x42384 (13.4GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information."
The I tried with a reduced (decimated) arrays.
This is the result:
polarpcolor.jpg
I don't understand what happens. Please help me!
Yeah, that doesn't look right. What happened is that since your tetanord is not monotonically increasing between 0 and 360 you get a wrapped surface where som patches overlap in the most annoying way.
Depending on how you want to reinterpolate your data you can do something like:
theta_i = linspace(0,2*pi,361); % As any sensible person does we do this in radians
mediau_i = linspace(0,7,701);
[mediau_i,theta_i] = meshgrid(mediau_i,theta_i);
mediaA_F1 = scatteredInterpolant(mediau,thetanord,media_a1);
mediaA_F2 = scatteredInterpolant(mediau.*cos(thetanord),...
mediau.*sin(thetanord),...
media_a1);
media_Ai1 = mediaA_F1(mediau_i,theta_i);
media_Ai2 = mediaA_F2(mediau_i.*cos(theta_i),mediau_i.*sin(theta_i));
[h,c]=polarPcolor(mediau(1,:),tetanord(:,1)'*180/pi,media_Ai1);
HTH
Sorry, but I having errors, yet.
This is the code used, following your suggestions:
theta_i = linspace(0,2*pi,361);
mediau_i = linspace(0,1,length(mediau));
[mediau_i,theta_i] = meshgrid(mediau_i,theta_i);
mediaA_F1 = scatteredInterpolant(mediau,tetanord,media_a1);
mediaA_F2 = scatteredInterpolant(mediau.*cos(tetanord),...
mediau.*sin(tetanord),...
media_a1);
media_Ai1 = mediaA_F1(mediau_i,theta_i);
media_Ai2 = mediaA_F2(mediau_i.*cos(theta_i),mediau_i.*sin(theta_i));
[h,c]=polarPcolor(mediau(:,1),tetanord(:,1)'*180/pi,media_Ai1);
and this is the error message:
Size of Z is : [361 42384]
Size of R is : [42384 1]
Size of theta is : [1 42384]
Error using polarPcolor (line 80)
dimension of Z does not agree with dimension of R and Theta
Try to find out why! Step 1, go trhough all possible permutations of Z R and theta.
Step 2: type "dbstop if error" on the command-line prompt, run the polarPcolor again - and you'll get a debug-prompt in the function where the error occurred, then you have command-line access to all variables in that workspace - as well as the possibility to jump further up (and down) the function-call-stack by "dbup" (and dbdown).
HTH

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

on 6 Feb 2019

Commented:

on 23 Dec 2020

Community Treasure Hunt

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

Start Hunting!