File Exchange

image thumbnail

Polar 2

version (3.86 KB) by

An update to Matlabs built-in polar.m

7 Ratings



View License

A polar plot script that allows selection of axis limits by the user, including negative radial limits. It is particularly appropriate for logarithmic data.
A known limitation is that datapoints outside the radial limits will still be drawn.

Comments and Ratings (30)

mat bst

Something wrong with the file, it just contains the license.txt file!!!

Cheng Li

Hi, I just downloaded this file, but it is in .zip format and I cannot expand it.. Can someone tell me what should I do? Thanks

That was exactly what I needed


Linus (view profile)

A very nice improvement compared to the orignial polar plotter! Though I have a problem:

When ever I try to plot multiple traces with radial limits in one figure, the colour is always blue.

example code:
polar2([0:2*pi; 0:2*pi]', [1:7 ; 7:-1:1]',[0 10])

Have any ideas to why?


Peter (view profile)

If there /is/ to be an updated version of polar2.m at any point, it would be fantastic if it could also give the user control over the number and or spacing of the rho-axis gridlines... something akin to the 'ytick' parameter in cartesian axes. Thanks again!


Peter (view profile)

Wow -thanks Daniel, I look forward to any updates that may be available!

Daniel Armyr

Daniel Armyr (view profile)

OK, I wrote an updated version that incormporates your ideas, Peter. However, as I am now a MathWorks employee, there might be issues with me publishing that update. I will comment again when and if an update is released.

Daniel Armyr

Daniel Armyr (view profile)

These are limitations in the current version of polar2, yes. But they are not limitations that are more complex than that maybe I can fix them tomorrow.


Peter (view profile)

Daniel - Thanks for filling the polar plot gap for those of us who work with dB attenuation. I've been using your older 'pp.m' for several years now. Despite it's girth and bugginess, I've come to love the control it grants over the graphical aspects of the plot, such as 'ThetaStartAngle' and 'ThetaDirection'.

I'm working on creating a GUI with a polar plot in it. Reading through the comments on the 'pp' page, I gather that we can't use pp to plot into existing axes (or subplots, for that matter), hence 'polar2.'

So, now I can plot my polar into the axes of my choice - Great! But, I seem to lose control over the orientation of the polar coordinate system and the theta direction. Is there a way to set 0 degrees at the top of the plot and plot clockwise?

Additionally, it appears that rho values that are more negative than the 'CenterValue' aren't truncated, as with pp.m. Instead, they appear to be plotted 'through' the center of the plot, 180 degrees off. in pseudo-code,

if rho < CenterValue
    plot( (theta - pi), (CenterValue - rho) )

Is this a fundamental limitation in polar2, or is there a workaround (other than setting CenterValue < min(rho) )?


Daniel Armyr

Daniel Armyr (view profile)

Well, you should be able to use the polar2(AX,...) syntax. I haven't tried it, but if that works wit the original polar, it should work with polar2.

It is always better if you can send the axes as an argument to the function rather than to first set the axes and then plotting. In GUIs, things can happen that change the CGA even between two lines of code in the same function.


LORENA (view profile)

Daniel, thank you very much. The answer is similar a your piece of advice. I do:


I have written a lot about set, get, gcf,gca... and now I have just got the answer! :)


LORENA (view profile)

The thing that I would like to know is how draw in the graphical user interface GUIDE, how programm my axes (objects handles).

I have two axes in my graphical user interface: PH and PV.

With polar is:
(theta=ang, rho=va)

How is with polar2?

Daniel Armyr

Daniel Armyr (view profile)

If I understand you correctly, this is what you would do:

subplot ( 2, 1, 1 );
polar2((1:360)*pi/360,-60*rand(1,360),[-60 0])
subplot ( 2, 1, 2 );
polar2((1:360)*pi/360,-60*rand(1,360),[-60 0])


LORENA (view profile)

Hello Daniel,
I have written you a pp.m. If I have understood you good, I writte you here. In my GUI I have two axes where I want to draw a radiation pattern (planes horizontal and vertical). The values are negative y therefore I want to use polar2.m. How can I draw in my axes? For example:



7ate9 (view profile)


Jochen (view profile)

Daniel Armyr

Daniel Armyr (view profile)

@senthil: I am sorry, but I do not udnerstand your question. You seem to have an idea of what your theta values shoudl be. In that case, can't you just set your theta values to what you want and plot it?


I am using ur polar2.m file for plotting. If i have some 2000 rho values in set A, Is it possible to push the data (theta) to start from say 700 to 2700. so i the initial part will be blank. This i need to do (by hold ON) on 4 set of values that will be over laid. so finally i will get concentric ring of values while the central 700 region is empty.

Daniel Armyr

Daniel Armyr (view profile)

@Faisal: Two examples are provided here in the thread. Try Judy's and Jerrys examples and see where that leads you.


Faisal (view profile)

mr daniel, can u send ur demo on this case..

i have case, and im using ur formula, but... the result i have is strange..
i mean the figure result its not logic to me...

Jerry Gump

Solution to my question is:

patch(get(h,'XData'),get(h,'YData'),[0 1 1]);
hold on;
t = 0:.01:2*pi;

Daniel Armyr

Daniel Armyr (view profile)

@Jerry: Sorry, there are few options for polar plotting in Matlab. Maybe if you ask in the newsgroup you might find something.

Jerry Gump

Do we have anything that works similar to shade command for rectangular plots? We am making a polar plot and I want to shade the region between the two angles.

Daniel Armyr

Daniel Armyr (view profile)

@Judy: Well, actually. This is the Mathworks original polar.m with just a few modifications to get the features I wanted. So unfortunately, I can't answer for that part of the code since I didn't write it.


Judy (view profile)

Actually, looking into this more, this actually does plot the graph, but the error keeps coming up, so I just commented the last part out. I don't think it is necessary? What was the purpose for making the mcode at the end? Thank you!!

Daniel Armyr

Daniel Armyr (view profile)

I redownloaded the code from here, and cut and pasted your two-line example directly into my command window. I get a nice flower-petal plot with no errors.

This file has only been tested with Matlab2009a and 2009b. What version are you running?


Judy (view profile)

The code is giving me an error of

??? Error using ==> makemcode>local_parse_input
Invalid input

Error in ==> makemcode at 38
[h,options] = local_parse_input(varargin{:});

Error in ==> polar2 at 249

when I try to plot a simple example for a polar plot with
t = 0:.01:2*pi;

What is going on?

I was looking exactly for this! It is strange that the "polar" function supplied by MATLAB does not provide the facility to set the axis limits. Thanks a lot!


Updated license


Fixed the drawing of multiple lines so they get different colors.


Reupploaded as the file did not get properly updated.


Now handles values less than minimum better. Reassigned copyright to MathWorks.


Added support for anglular limits and cropping out-of-bounds values.


Edited the description.

MATLAB Release
MATLAB 7.14 (R2012a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video