Thread Subject: Select data to plot using checkboxes

Subject: Select data to plot using checkboxes

From: Linda

Date: 22 Nov, 2008 19:58:01

Message: 1 of 4

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?

Thanks in advance.
/Linda

Subject: Select data to plot using checkboxes

From: Johan Carlson

Date: 22 Nov, 2008 20:17:01

Message: 2 of 4

"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?
>
> Thanks in advance.
> /Linda

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.

Use the same principle for the other plots, but with other tags.

/JC

Subject: Select data to plot using checkboxes

From: Walter Roberson

Date: 22 Nov, 2008 23:52:02

Message: 3 of 4

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)?

Subject: Select data to plot using checkboxes

From: Linda

Date: 26 Nov, 2008 15:42:01

Message: 4 of 4

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)?

Thanks for the answers. I'm currently using both approaches (in different functions), so it was nice to get different views on the same question.
/Linda

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Linda 22 Nov, 2008 15:00:22
checkbox Linda 22 Nov, 2008 15:00:22
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com