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 日

0 投票

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 件のコメント

Man Lok Lee
Man Lok Lee 2021 年 8 月 23 日
oh yes sorry, I did have pax inside polarplot() , but that still didnt work
Adam Danz
Adam Danz 2021 年 8 月 23 日
It needs to be applied to hold, too. See updated answer.
Man Lok Lee
Man Lok Lee 2021 年 8 月 23 日
Thanks very much it worked!
But why the hold has to be outside the for loop and not inside?
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 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

2021 年 8 月 23 日

編集済み:

2021 年 8 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by