double plot not properly working with checkboxes in appdesigner Matlab (R2020a)

i have designed a interface for single or double plot which i control through Check Boxes. inshort the problem is when i run the code first time its double plot perfectly but when uncheck one checkbox and recheck then double plot not shown.
it is working 90% fine
when i click first checkbox it plot... i uncheck it disappears.. same for second choice.
when i click both checkboxes it double plot and when it uncheck "S" only "L" plot shows.
but problem start when at this stage i again click "S" checkbox while "L" checkbox is already selected then it only plotting "S", it should again double plot. this may be little bit confusing to explain thats why i attached GIF for demonstration... also code file attached... kindly suggest some solution.
function plotwidth(app)
M % Property Used
a = 0:0.1:2*pi;
b = sin(a);
c = cos(a);
if app.LCheckBox.Value && ~app.SCheckBox.Value
app.UIAxes.cla;
app.M = plot(app.UIAxes,a,b);
elseif app.SCheckBox.Value && ~app.LCheckBox.Value
app.UIAxes.cla;
app.M = plot(app.UIAxes,a,c);
elseif app.LCheckBox.Value && app.SCheckBox.Value
app.N = plot(app.UIAxes,a,b);
hold(app.UIAxes);
app.M = plot(app.UIAxes,a,c);
else
app.M.Visible = 'off';
end
end

4 Comments

maybe this will work for you:
fig=figure();
button1=uicontrol(fig,'Style','checkbox','Position',[100 1 50 22],'String','S');
button2=uicontrol(fig,'Style','checkbox','Position',[10 1 50 22],'String','L');
hold on
plot1 = plot(1:10);
plot2 = plot(10:-1:1);
while 0<1
if button1.Value==0
set(plot1(1),'Visible','off');
elseif button1.Value==1
set(plot1(1),'Visible','on');
end
if button2.Value==0
set(plot2(1),'Visible','off');
elseif button2.Value==1
set(plot2(1),'Visible','on');
end
pause(0.1)
end
Dear stijn very Thanks... Ur code is exactly working according to my requirement.
it seems there is some sort of technical issue from matlab side... Stijn has answered the question but in my profile its showing zero answer for this question.... when i open the question so no "Accept Answer" button is showing... i will also mail this to matllab...But once again Dear Stijn Thanks for ur support. Best Regard... As the Server Issue resolves i will accept this answer.
Stijn's comment/answer is in comment section, therefore can't be accepted as an answer.

Answers (0)

This question is closed.

Asked:

on 18 Oct 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!