Toggle visibility of plots, on the same figure?

153 Ansichten (letzte 30 Tage)
Roger Breton
Roger Breton am 12 Jan. 2022
Kommentiert: Roger Breton am 12 Jan. 2022
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 Kommentar
Roger Breton
Roger Breton am 12 Jan. 2022
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!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Roger Breton
Roger Breton am 12 Jan. 2022
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 Kommentare
Roger Breton
Roger Breton am 12 Jan. 2022
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!!!!
Roger Breton
Roger Breton am 12 Jan. 2022
I'll take a look at the the guidata struct. Thanks for the leg up!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by