Toggle visibility of plots, on the same figure?

Attached is the current state of my "project" for which I have SO MANY questions...
First, as I experimented with the script this morning, it dawned on me that my script value would be enhanced by a checkbox that would toggle on and off the visibility of the trisurf plot, so that, I could isolate the data points from the gamut volume to better study their relationship :
Adding a uicontrol checkbox to the script should not be difficult but I sense that I would have to restructure the script very differently? Such that, from the callback function I could issue the call to the trisurf function? Or are there figure or axes options I don't know about that would make this easier?

1 Comment

A search for "Show or hide figure plot" turned the Plot Browser!!!
Wow! Thank you Mathworks, it's almost what I want, as the figure is "frozen" (can't interact with it while the Plot Browser is active). But it's mighty strong!!

Sign in to comment.

 Accepted Answer

Almost there! This is what I have, now :
You can see my checkbox, top, left-hand, circled in red -- wow! I added this code to create the control :
cb = uicontrol('Style','checkbox','String','triSurf','Position',[10 500 75 150],'Value',1,'Callback',@checkBoxCallback);
cb.Visible = 'on';
Then I added this function to handle the callback :
function checkBoxCallback(source, event)
global h1;
value = get(source,'Value');
if value == 1
set(h1,'Visible','off');
else
set(h1,'Visible','on');
end
end
Problem is -- please excuse my ignorance -- the checkbox state? When the script is ran, initially, the Value = 1 option in the declaration sets the checkbox state to checked, as far as I can see. This is how the control shows up in the interface. I think it's logical to have the checkbox checked since the trisurf plot is initially visible. When I click on the ckeckbox, however, nothing happens : I have to click one more time and then, the checkbox becomes unchecked but the trisurf is still visible? It's only when I click a third time that the checkbox starts to work as 'expected'. I attached the new code. It's not the end of the world but...
One newbie question in passing, if I may...
I'm using global variables 'sparingly'... Are there better ways to do this, without getting too overly complex?

3 Comments

Just a small edit suggestion: you should store the handles you want to interact with in the guidata struct. That way you don't need global variables.
As for the other issue you mentioned, I don't understand your problem well enough to be able to solve it.
Right after initial launch, right after pressing the Run button, I get this :
As you can see, the checkbox is checked. Which is the expected behavior.
Now, this is what happens when I first try to uncheck :
The checkbox is unchecked -- yet, the plot is still visible?
I click the checkbox... and this is what I get :
Now the checkbox is checked YET the plot is not visible?
One more round of clicking and this is what I get :
Do you see what is going on? It is as though the checked state does not match the visibility of the plot.
I changed the initial value in the code back to 0 and changed my code in the function this way :
if value == 0
set(h1,'Visible','off');
else
set(h1,'Visible','on');
end
And now, everything is perfect!!!!
I'll take a look at the the guidata struct. Thanks for the leg up!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!