Matlab: Polarplot

Polar-Plots

(German) If you use Matlabtikz and you want to create a polar plot, latex does not plot the axis. That's why i wrote this polargrid function.

polartikzlabel(angleticks,abs,ticks,absdeg,anglestr,absstr,round1)

Therefor "angleticks" the amount of subdivisions of the angle, "abs" the radius, "ticks" the amunt of the subdivisions of the radial scale, "absdeg" the angle of the radialtext.
"anglestr" is the text of the anglescale "absstr" is the text of the radial scale. "round1" is the amount of internal decimal places.

Dies kann wie folgt aussehen: polartikzlabel(5,1,6,40,'angle','radial',3)

Source code:

function polargrid(angleticks,abs,ticks,absdeg,anglestr,absstr,round1)
%angleticks set the number of ticks in equidistant angles.
%abs set the radius of the polarplot.
%ticks set the number of ticks in equidistant radialskale.
%absdeg set the degree of the radialaxis.
%anglestr set the labeling of the angleaxis.
%absstr set the labeling of the radialaxis.
%the number of positions behind the point.

  
%Delete the text
delete(findall(gcf,'type','text'));

%Delete the grid
set(0,'ShowHiddenHandles','on')
set(findobj(findobj(get(gca,'Children'),'Type','Line'),'LineStyle','-'),{'Visible'},{'off'});
hold on;
%Declare the variables
value1=360/angleticks;
value2=abs/ticks;
if nargin < 5
    anglestr = 'angle';
    absstr = 'radial';
end
%round the labels
if nargin < 7
    round1 = 2;
end
round1 = (10)^(round1);
angles =round([0:value1*round1:(360-value1)*round1])/(round1);
rho = round([0:value2*round1:abs*round1])/(round1)

n=numel(rho);
rad=rho(n)+rho(n)/10;

%Draw the angle-scale
amount = numel(angles);
X = [zeros(amount,1), rho(n)*cos(angles(1:amount)'./180*pi)];
Y = [zeros(amount,1), rho(n)*sin(angles(1:amount)'./180*pi)];

plot(X',Y','Color',[0.8 0.8 0.8]);

%Draw the radial-scale
anglegrid = [0:pi/100:2*pi];
Xgrid = rho'* cos(anglegrid);
Ygrid = rho'* sin(anglegrid);
plot(Xgrid',Ygrid','Color',[0.8 0.8 0.8]);


%Draw the skalevalues
Xangle = rad.*cos(angles./180*pi)-abs/20;
Yangle = rad.*sin(angles./180*pi);
text(Xangle,Yangle,num2cell(angles));

Xrho = rho*cos(absdeg/180*pi);
Yrho = rho*sin(absdeg/180*pi)+sin(absdeg/180*pi)*abs/10;
text(Xrho,Yrho,num2cell(rho));

%Write the labels
text(1.1*abs*cos(absdeg/180*pi),1.3*abs*sin(absdeg/180*pi),absstr);
text(abs+abs/5,0,anglestr);


Kommentare

Beliebte Posts aus diesem Blog

Easy Plots in HTML/PHP with Google Charts

Matlab: 3D Coordinate System Rotations with Vectors

Matlab: Dijkstra methode - shortest way on gradient (small neighborhood)