@MathWorks Support Team Can you please let me know how the XDdata/YData or the vertices are being obtained in the function polarpattern? Thankyou in advance.
How to patch the area under curve for a polarplot?
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to create a figure as shown below using "polarplot" function. Can anyone please help me regarding this?

3 Kommentare
Star Strider
am 16 Aug. 2025
Bearbeitet: Walter Roberson
am 16 Aug. 2025
Include the URL of this thread in your note to MathWorks.
Please post their reply sonewhere in this thread. (Note that what you want may be proprietary information.)
Ron
am 17 Aug. 2025
I completely agree with the last point of yours and in that case it is completely fine for them to not disclose it here. However I have been able to find and alternate way of getting my desired results and I have that it might be usefull for other. I am posting the code that I have written.
Antworten (3)
Chuguang Pan
am 13 Aug. 2025
There is a similar question in https://ww2.mathworks.cn/matlabcentral/answers/451422-how-to-use-patch-fill-on-a-polarplot, this may be helpful.
Ron
am 17 Aug. 2025
Verschoben: Star Strider
am 20 Aug. 2025
clc; clear all;
h1 = helix(Radius=31e-3, Width=1.2e-3, Turns=4); %%% Input Data for pattern function
h2 = helix(Radius=26e-3, Width=1.2e-3, Turns=4);%%% Input Data for pattern function
H1 = pattern(h1,1.8e9,0,0:1:360); %%% Input Data for polarpattern function
H2 = pattern(h2,1.8e9,0,0:1:360); %%% Input Data for polarpattern function
% % Plot the polar pattern.
figure
P0 = polarpattern(H1,'AntennaMetrics',1,'FontName','Times New Roman'); hold on
P0 = polarpattern(H2);
%%%%%%%%%%%%%%%%%%%%% Finding the lobes
pp=findLobes(P0,1); %%% It is important to find the lobes to match their indices with those of XData/YData
pp1=fieldnames(pp);
XYmain=pp.mainLobe.extent
XYside=pp.sideLobes.extent;
XYback=pp.backLobe.extent;
aa0=P0.Parent.Parent.CurrentFigure.CurrentAxes.Children;
aa=(get(aa0,'Tag'));
for ii=1:length(aa)
PatchLen(ii,:)=convertCharsToStrings(aa{ii});
end
ind=contains(PatchLen,"Lobe");
[aa,bb]=find(ind==1);
%%%%%%%%%%%%%%%%%%%%% Finding the XData and YData corresponding to the patch
for nn=1:length(bb)
xx1{:,nn}=P0.Parent.Parent.CurrentFigure.CurrentAxes.Children(aa(nn)).XData(1:end-2);
yy1{:,nn}=P0.Parent.Parent.CurrentFigure.CurrentAxes.Children(aa(nn)).YData(1:end-2);
end
%%%%%%%%%%%%%%%%%%%%% Default patch sequence is Side left lobe, Side right lobe, Back lobe and Front lobe
%%%%%%%%%%%%%%%%%%%%% this is different from the sequence of the findLobes fucntion hence to match both of them do this
if length(bb)==4
xx1([1 2 3 4])=xx1([4 2 3 1]);yy1([1 2 3 4])=yy1([4 2 3 1]);
elseif length(bb)==3
xx1([1 2 3])=xx1([3 2 1]);yy1([1 2 3])=yy1([3 2 1]);
elseif length(bb)==2
xx1([1 2])=xx1([2 1]);yy1([1 2])=yy1([2 1]);
end
%%%%%%%%%%%%%%%%%%%%% Create single XData and YData matrices of points corresponding to the patches
xx3=[]; yy3=[];
for nn=1:length(bb)
xx3=vertcat(xx3,xx1{1,nn});
yy3=vertcat(yy3,yy1{1,nn});
end
%%%%%%%%%%%%%%%%%%%%% If you want to compare 2 patterns and use patches to show regions of x% relative erro then use this part
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Start
DataDiff=abs(((H1+100)-(H2+100))./(H1+100))*100;
figure
plot(H2,"--"); hold on
plot(H1);
plot(DataDiff);
ind=DataDiff<2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Condition for error
DataDiffInd=diff([0;ind;0]);
beginsBlue=find(DataDiffInd==1);
endsBlue=find(DataDiffInd==-1)-1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ends
XDataPatch = circshift(xx3,XYmain(1)-1); %%%%%%%%% Match the patch coordinates with those of Lobes
YDataPatch = circshift(yy3,XYmain(1)-1); %%%%%%%%% Match the patch coordinates with those of Lobes
figure
P1 = polarpattern(H1',...
'FontName','Times New Roman',...
'FontSize',13); hold on
P1 = polarpattern(H2',...
'FontName','Times New Roman',...
'FontSize',13);
P1.MagnitudeAxisAngle=80;
P1.AngleResolution=30;
%%%%If you want custom patches then use this template
%% XDataPatchN1=[XDataPatch(start:end);0];
%% YDataPatchN1=[YDataPatch(start:end);0];
%% PatchyThings(XDataPatchN1,YDataPatchN1,"Blue");
n=length(beginsBlue);
for nn=1:n
if nn==1
XDataPatchN1=[XDataPatch(beginsBlue(nn):endsBlue(nn));0];
YDataPatchN1=[YDataPatch(beginsBlue(nn):endsBlue(nn));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Blue");
XDataPatchN1=[XDataPatch(endsBlue(nn):beginsBlue(nn+1));0];
YDataPatchN1=[YDataPatch(endsBlue(nn):beginsBlue(nn+1));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Red");
elseif 1<nn && nn<n
XDataPatchN1=[XDataPatch(beginsBlue(nn):endsBlue(nn));0];
YDataPatchN1=[YDataPatch(beginsBlue(nn):endsBlue(nn));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Blue");
XDataPatchN1=[XDataPatch(endsBlue(nn):beginsBlue(nn+1));0];
YDataPatchN1=[YDataPatch(endsBlue(nn):beginsBlue(nn+1));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Red");
else
if ismember(1,beginsBlue)
XDataPatchN1=[XDataPatch(beginsBlue(nn):endsBlue(nn));XDataPatch(1)];
YDataPatchN1=[YDataPatch(beginsBlue(nn):endsBlue(nn));YDataPatch(1)];
PatchyThings(XDataPatchN1,YDataPatchN1,"Blue");
XDataPatchN1=[XDataPatch(endsBlue(nn):beginsBlue(nn+1));0];
YDataPatchN1=[YDataPatch(endsBlue(nn):beginsBlue(nn+1));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Red");
else
XDataPatchN1=[XDataPatch(beginsBlue(nn):endsBlue(nn));0];
YDataPatchN1=[YDataPatch(beginsBlue(nn):endsBlue(nn));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Blue");
XDataPatchN1=[XDataPatch(endsBlue(nn):end);0];
YDataPatchN1=[YDataPatch(endsBlue(nn):end);0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Red");
XDataPatchN1=[XDataPatch(end);XDataPatch(1:beginsBlue(1));0];
YDataPatchN1=[YDataPatch(end);YDataPatch(1:beginsBlue(1));0];
PatchyThings(XDataPatchN1,YDataPatchN1,"Red");
end
end
end
path='E:\Scatterer\Figures\'
exportgraphics(gcf,strcat(path,"Fig1",".png"),Resolution=300);
function PatchyThings(XDataPatchN1,YDataPatchN1,colr)
if strcmp(colr,'Red')
clr=[0.8 0.4 0.4];
else
clr=[0.6 0.7788 0.8964];
end
patch("XData",[0 XDataPatchN1'],"YData",[0 YDataPatchN1'],"ZData",[0 ones([1 length(YDataPatchN1)+1])*0.01],...
'FaceAlpha',0.65,...
'FaceColor',clr,...
'EdgeColor','none')
end

0 Kommentare
Ron
am 18 Aug. 2025
For anyone who wants to know how to do it, please follow this https://in.mathworks.com/matlabcentral/answers/2179324-how-to-patch-the-area-under-curve-for-a-polarplot#comment_3339489
1 Kommentar
Star Strider
am 20 Aug. 2025
@Ron --
I moved your earlier Comment to an answer. You can accept it, although no reputation points for accepting your own answer. In this instance, that only indicates that you came up with a solution to your problem.
Siehe auch
Kategorien
Mehr zu Polar Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!