polarplot app.panel with condition in app designer

2 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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