polarplot app.panel with condition in app designer

조회 수: 2 (최근 30일)
Man Lok Lee
Man Lok Lee 2021년 8월 23일
편집: Adam Danz 2021년 8월 23일
Hi everyone,
I currently need a way to do a polarplot in app designer with some conditions. I tried a normal polatplot in a panel and it worked but when I tried doing it with if statements it only showed up with one dot.
I have tested it in a script and it worked.
So only the for loop and the if statements do not work in app designer at the moment.
Does anyone know how to get around it or fix it?
would be much appreciated with any help.
I put this code under a button callback.
y1 = [1,2,3,4,5,6,7,8,9,10,14,13,12,11,1,1,1,1,1,1,1,1,1,1] %for example
dotsize = 30;
n = 7; %no. of turns
theta1 = linspace(0,n*2*pi,length(y1));
rho1 = linspace(1,2,numel(theta1));
pax = polaraxes(app.Panel);
for i = 1:length(y1)
for ii = y1(i)
if ii < 3 % if score is below 3, colour red
polarplot(theta1(i),rho1(i),'r.','Markersize',dotsize);
hold on
elseif 3 <= ii && ii < 8 % if score is between 3 and 8 clour green
polarplot(theta1(i),rho1(i),'g.','Markersize',dotsize);
hold on
elseif 8 <= ii && ii <= 14 % if score is greater than 8, colour blue
polarplot(theta1(i),rho1(i),'b.','Markersize',dotsize);
hold on
end
end
end
pax.ThetaDir = 'clockwise';
pax.FontSize = 12;
pax.ThetaZeroLocation = 'top';
thetaticks(pax,[0 30 60 90 120 150 180 210 240 270 300 330])
thetaticklabels(pax,{'00:00','02:00','04:00','06:00','08:00','10:00','12:00',...
'14:00','16:00','18:00','20:00','22:00'})
rticks(pax,[])
  댓글 수: 1
Man Lok Lee
Man Lok Lee 2021년 8월 23일
Correction: I did have polarplot(pax,theta1(i),rho1(i),'r.','Markersize',dotsize);
I tried it and it still did't work

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2021년 8월 23일
편집: Adam Danz 2021년 8월 23일
I think the problem is that you're not specifying the axes but that doesn't explain why a blue dot appears and you should have seen the image appear on an external figure if my assumption is correct. Try this.
polarplot(pax, theta1(i),rho1(i),'r.','Markersize',dotsize);
% add this ^^^ to all plolarplot() calls
You also need to apply the handle to the hold command and all graphics functions. The hold function only needs to be called once so I've moved it outside of the loop in the block below.
y1 = [1,2,3,4,5,6,7,8,9,10,14,13,12,11,1,1,1,1,1,1,1,1,1,1] %for example
dotsize = 30;
n = 7; %no. of turns
theta1 = linspace(0,n*2*pi,length(y1));
rho1 = linspace(1,2,numel(theta1));
pax = polaraxes(app.Panel);
hold(pax, 'on')
for i = 1:length(y1)
for ii = y1(i)
if ii < 3 % if score is below 3, colour red
polarplot(pax, theta1(i),rho1(i),'r.','Markersize',dotsize);
elseif 3 <= ii && ii < 8 % if score is between 3 and 8 clour green
polarplot(pax, theta1(i),rho1(i),'g.','Markersize',dotsize);
elseif 8 <= ii && ii <= 14 % if score is greater than 8, colour blue
polarplot(pax, theta1(i),rho1(i),'b.','Markersize',dotsize);
end
end
end
pax.ThetaDir = 'clockwise';
pax.FontSize = 12;
pax.ThetaZeroLocation = 'top';
thetaticks(pax,[0 30 60 90 120 150 180 210 240 270 300 330])
thetaticklabels(pax,{'00:00','02:00','04:00','06:00','08:00','10:00','12:00',...
'14:00','16:00','18:00','20:00','22:00'})
rticks(pax,[])
  댓글 수: 5
Adam Danz
Adam Danz 2021년 8월 23일
편집: Adam Danz 2021년 8월 23일
It doesn't have to be outside of the loop but calling it more than once is pointless. When you call hold(ax,'on') it sets the NextPlot property so the second time you call it, the propery is already set. By moving it outside of the loop, you're eliminating redundancy which results in cleaner code.
Man Lok Lee
Man Lok Lee 2021년 8월 23일
Okay thanks for the advice!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by