Search code examples
matlabplotmatlab-figurepolar-coordinates

To draw polar plot where points in order by column 1?


Data

0   0.867779926444275
15  0.895866066532554
30  0.791816991652543
45  0.729582701499042
60  0.510896493274811
75  0.349659272558701
90  0.255383327300393
105 0.383729598278156
120 0.604795433670792
135 0.731177670225856
150 0.783135047098391
165 0.984715658218028

Code in Matlab

polar(data(:,1), data(:,2), 'k-'); 

which gives

enter image description here

You see that the first point (0) is connected to the 2nd point (135). I would like that points are connected in order like 0 to 15, 15 to 30, ..., 150 to 165, and eventually 165 to 0 possibly.

How can you draw polar plot where points are connected by the order in column 1?


Solution

  • polar expects the first input to be in radians, not in degrees. So, use

    polar(data(:,1)*pi/180, data(:,2), 'k-');
    

    With your example values, this gives

    enter image description here

    To connect last point to first, just repeat the first point at the end:

    polar(data([1:end 1],1)*pi/180, data([1:end 1],2), 'k-');
    

    enter image description here