Walter Roberson <roberson@hushmail.com> wrote in message <bW0Wk.24031$9Z6.1106@newsfe01.iad>...
> Johan Carlson wrote:
> > "Linda " <lindakristensen1@hotmail.com> wrote in message <gg9o89$8tj$1@fred.mathworks.com>...
> >> Hi
> >> I'm making a GUI, where I have four checkboxes each representing a dataset (data1, data2, data3, data4). I would like to be able to plot one or multiple dataset on the same axes depending on whether the checkbox is selected or not, i.e. the value of the checkbox is 0 (not selected) or 1 (selected). For example if value of checkbox1 is 1, data1 is plotted and if value of checkbox1 is 0, the data1 is removed from the axes / not plotted.
> >>
> >> I've tried to make an if-construction in the callback function for each checkbox:
> >> if get(checkbox1, value) ==1
> >> plot(data1)
> >> hold on
> >> elseif get(checkbox, value) == 0
> >> hold off
> >>
> >> And that means that I can select and plot multiple data, i.e. when checkbox1 and checkbox2 is selected, data1 and data2 is plotted on the same axes. But when checkbox1 is deselected, the graph for data1 is not removed.
> >> Any ideas or suggestions to do that?
>
> > When you create the plots, do this:
>
> > p1 = plot(data1);
> > set(p1,'tag','p1');
>
> > Then if when you uncheck the box, do this:
> > delete(findobj('tag','p1'))
>
> > The tags allow you to find the objects and "kill" them.
>
> Unless each of the plots takes a long time to calculate or render, I recommend
> a slightly different approach for this situation. I suggest rendering each of the
> plots at the start, each tagged uniquely; then when a particular plot is to show
> up or not show up according to the state of the check box, you can just set
>
> visstates = {'off', 'on'};
>
> thisisvis = visstates{1 + get(checkbox1, 'Value')};
> set(findobj('tag','p1'), 'Visible', thisisvis)
>
> You don't even need any if/else statements for this logic.
>
> --
> .signature note: I am now avoiding replying to unclear or ambiguous postings.
> Please review questions before posting them. Be specific. Use examples of what you mean,
> of what you don't mean. Specify boundary conditions, and data classes and value
> relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?
Hello,
I tried to do something very similar by defining all my plots on the opening function of my GUI :
handles.p1=plot(handles.PressureGraph,handles.Data(:,1),handles.Data(:,2));
set(handles.p1, 'Visible', 'off');
handles.t1=plot(handles.TempGraph,handles.Data(:,1),handles.Data(:,3));
set(handles.t1, 'Visible', 'off');
But I am unable to access them in my checkbox callback function :
guidata(hObject, handles);
visstates = {'off', 'on'};
thisisvis = visstates{1 + get(hObject, 'Value')};
set(handles.p1, 'Visible', thisisvis);
set(handles.t1, 'Visible', thisisvis);
handles.p1 is not a graphic handle anymore. This is why I get the following error :
??? Error using ==> set
Invalid handle object.
How can I share handle objects between callback functions ? I thought defining them as handles.variable should do the job but it is not the case.
Thanks a lot for any help.
> Johan Carlson wrote:
> > "Linda " <lindakristensen1@hotmail.com> wrote in message <gg9o89$8tj$1@fred.mathworks.com>...
> >> Hi
> >> I'm making a GUI, where I have four checkboxes each representing a dataset (data1, data2, data3, data4). I would like to be able to plot one or multiple dataset on the same axes depending on whether the checkbox is selected or not, i.e. the value of the checkbox is 0 (not selected) or 1 (selected). For example if value of checkbox1 is 1, data1 is plotted and if value of checkbox1 is 0, the data1 is removed from the axes / not plotted.
> >>
> >> I've tried to make an if-construction in the callback function for each checkbox:
> >> if get(checkbox1, value) ==1
> >> plot(data1)
> >> hold on
> >> elseif get(checkbox, value) == 0
> >> hold off
> >>
> >> And that means that I can select and plot multiple data, i.e. when checkbox1 and checkbox2 is selected, data1 and data2 is plotted on the same axes. But when checkbox1 is deselected, the graph for data1 is not removed.
> >> Any ideas or suggestions to do that?
>
> > When you create the plots, do this:
>
> > p1 = plot(data1);
> > set(p1,'tag','p1');
>
> > Then if when you uncheck the box, do this:
> > delete(findobj('tag','p1'))
>
> > The tags allow you to find the objects and "kill" them.
>
> Unless each of the plots takes a long time to calculate or render, I recommend
> a slightly different approach for this situation. I suggest rendering each of the
> plots at the start, each tagged uniquely; then when a particular plot is to show
> up or not show up according to the state of the check box, you can just set
>
> visstates = {'off', 'on'};
>
> thisisvis = visstates{1 + get(checkbox1, 'Value')};
> set(findobj('tag','p1'), 'Visible', thisisvis)
>
> You don't even need any if/else statements for this logic.
>
> --
> .signature note: I am now avoiding replying to unclear or ambiguous postings.
> Please review questions before posting them. Be specific. Use examples of what you mean,
> of what you don't mean. Specify boundary conditions, and data classes and value
> relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?
Hello,
I tried to do something very similar by defining all my plots on the opening function of my GUI :
handles.p1=plot(handles.PressureGraph,handles.Data(:,1),handles.Data(:,2));
set(handles.p1, 'Visible', 'off');
handles.t1=plot(handles.TempGraph,handles.Data(:,1),handles.Data(:,3));
set(handles.t1, 'Visible', 'off');
But I am unable to access them in my checkbox callback function :
guidata(hObject, handles);
visstates = {'off', 'on'};
thisisvis = visstates{1 + get(hObject, 'Value')};
set(handles.p1, 'Visible', thisisvis);
set(handles.t1, 'Visible', thisisvis);
handles.p1 is not a graphic handle anymore. This is why I get the following error :
??? Error using ==> set
Invalid handle object.
How can I share handle objects between callback functions ? I thought defining them as handles.variable should do the job but it is not the case.
Thanks a lot for any help.