Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Select data to plot using checkboxes
Date: Sat, 22 Nov 2008 20:17:01 +0000 (UTC)
Organization: Lulea University of Technology
Lines: 30
Message-ID: <gg9pbt$lji$1@fred.mathworks.com>
References: <gg9o89$8tj$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227385021 22130 172.30.248.37 (22 Nov 2008 20:17:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 22 Nov 2008 20:17:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1595763
Xref: news.mathworks.com comp.soft-sys.matlab:502526


"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