How to patch the area under curve for a polarplot?

140 次查看(过去 30 天)
I want to create a figure as shown below using "polarplot" function. Can anyone please help me regarding this?
  3 个评论
Star Strider
Star Strider 2025-8-16,12:58
编辑:Walter Roberson 2025-8-16,19:47
It would be best for you to Contact Support.
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
Ron 2025-8-17,10:20
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.

请先登录,再进行评论。

回答(3 个)

Chuguang Pan
Chuguang Pan 2025-8-13,6:44
  1 个评论
Ron
Ron 2025-8-13,7:04
Thank you so much for taking out time to reply but the answere says that this feature works for the version 2025a whereas I have 2023a.

请先登录,再进行评论。


Ron
Ron 2025-8-17,10:21
移动:Star Strider 2025-8-20,12:04
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

Ron
Ron 2025-8-18,14:56
  1 个评论
Star Strider
Star Strider 2025-8-20,12:08
@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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by