Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!bigfeed2.bellsouth.net!news.bellsouth.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe01.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Select data to plot using checkboxes
References: <gg9o89$8tj$1@fred.mathworks.com> <gg9pbt$lji$1@fred.mathworks.com>
In-Reply-To: <gg9pbt$lji$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 42
Message-ID: <bW0Wk.24031$9Z6.1106@newsfe01.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe01.iad 1227397895 24.79.146.116 (Sat, 22 Nov 2008 23:51:35 UTC)
NNTP-Posting-Date: Sat, 22 Nov 2008 23:51:35 UTC
Date: Sat, 22 Nov 2008 17:52:02 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:502558


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