<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239742</link>
    <title>MATLAB Central Newsreader - Select data to plot using checkboxes</title>
    <description>Feed for thread: Select data to plot using checkboxes</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 22 Nov 2008 19:58:01 -0500</pubDate>
      <title>Select data to plot using checkboxes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239742#612598</link>
      <author>Linda </author>
      <description>Hi&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
I've tried to make an if-construction in the callback function for each checkbox:&lt;br&gt;
if get(checkbox1, value) ==1&lt;br&gt;
plot(data1)&lt;br&gt;
hold on&lt;br&gt;
elseif get(checkbox, value) == 0&lt;br&gt;
hold off&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
Any ideas or suggestions to do that?&lt;br&gt;
&lt;br&gt;
Thanks in advance.&lt;br&gt;
/Linda</description>
    </item>
    <item>
      <pubDate>Sat, 22 Nov 2008 20:17:01 -0500</pubDate>
      <title>Re: Select data to plot using checkboxes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239742#612601</link>
      <author>Johan Carlson</author>
      <description>&quot;Linda &quot; &amp;lt;lindakristensen1@hotmail.com&amp;gt; wrote in message &amp;lt;gg9o89$8tj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I've tried to make an if-construction in the callback function for each checkbox:&lt;br&gt;
&amp;gt; if get(checkbox1, value) ==1&lt;br&gt;
&amp;gt; plot(data1)&lt;br&gt;
&amp;gt; hold on&lt;br&gt;
&amp;gt; elseif get(checkbox, value) == 0&lt;br&gt;
&amp;gt; hold off&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; Any ideas or suggestions to do that?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks in advance.&lt;br&gt;
&amp;gt; /Linda&lt;br&gt;
&lt;br&gt;
When you create the plots, do this:&lt;br&gt;
&lt;br&gt;
p1 = plot(data1);&lt;br&gt;
set(p1,'tag','p1');&lt;br&gt;
&lt;br&gt;
Then if when you uncheck the box, do this:&lt;br&gt;
delete(findobj('tag','p1'))&lt;br&gt;
&lt;br&gt;
The tags allow you to find the objects and &quot;kill&quot; them.&lt;br&gt;
&lt;br&gt;
Use the same principle for the other plots, but with other tags.&lt;br&gt;
&lt;br&gt;
/JC</description>
    </item>
    <item>
      <pubDate>Sat, 22 Nov 2008 23:52:02 -0500</pubDate>
      <title>Re: Select data to plot using checkboxes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239742#612633</link>
      <author>Walter Roberson</author>
      <description>Johan Carlson wrote:&lt;br&gt;
&amp;gt; &quot;Linda &quot; &amp;lt;lindakristensen1@hotmail.com&amp;gt; wrote in message &amp;lt;gg9o89$8tj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Hi&lt;br&gt;
&amp;gt;&amp;gt; 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.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; I've tried to make an if-construction in the callback function for each checkbox:&lt;br&gt;
&amp;gt;&amp;gt; if get(checkbox1, value) ==1&lt;br&gt;
&amp;gt;&amp;gt; plot(data1)&lt;br&gt;
&amp;gt;&amp;gt; hold on&lt;br&gt;
&amp;gt;&amp;gt; elseif get(checkbox, value) == 0&lt;br&gt;
&amp;gt;&amp;gt; hold off&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; 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.&lt;br&gt;
&amp;gt;&amp;gt; Any ideas or suggestions to do that?&lt;br&gt;
&lt;br&gt;
&amp;gt; When you create the plots, do this:&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; p1 = plot(data1);&lt;br&gt;
&amp;gt; set(p1,'tag','p1');&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; Then if when you uncheck the box, do this:&lt;br&gt;
&amp;gt; delete(findobj('tag','p1'))&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; The tags allow you to find the objects and &quot;kill&quot; them.&lt;br&gt;
&lt;br&gt;
Unless each of the plots takes a long time to calculate or render, I recommend&lt;br&gt;
a slightly different approach for this situation. I suggest rendering each of the&lt;br&gt;
plots at the start, each tagged uniquely; then when a particular plot is to show&lt;br&gt;
up or not show up according to the state of the check box, you can just set&lt;br&gt;
&lt;br&gt;
visstates = {'off', 'on'};&lt;br&gt;
&lt;br&gt;
thisisvis = visstates{1 + get(checkbox1, 'Value')};&lt;br&gt;
set(findobj('tag','p1'), 'Visible', thisisvis) &lt;br&gt;
&lt;br&gt;
You don't even need any if/else statements for this logic.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
.signature note: I am now avoiding replying to unclear or ambiguous postings.&lt;br&gt;
Please review questions before posting them. Be specific. Use examples of what you mean,&lt;br&gt;
of what you don't mean. Specify boundary conditions, and data classes and value&lt;br&gt;
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?</description>
    </item>
    <item>
      <pubDate>Wed, 26 Nov 2008 15:42:01 -0500</pubDate>
      <title>Re: Select data to plot using checkboxes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239742#613407</link>
      <author>Linda </author>
      <description>Walter Roberson &amp;lt;roberson@hushmail.com&amp;gt; wrote in message &amp;lt;bW0Wk.24031$9Z6.1106@newsfe01.iad&amp;gt;...&lt;br&gt;
&amp;gt; Johan Carlson wrote:&lt;br&gt;
&amp;gt; &amp;gt; &quot;Linda &quot; &amp;lt;lindakristensen1@hotmail.com&amp;gt; wrote in message &amp;lt;gg9o89$8tj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Hi&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; I've tried to make an if-construction in the callback function for each checkbox:&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; if get(checkbox1, value) ==1&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; plot(data1)&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; hold on&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; elseif get(checkbox, value) == 0&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; hold off&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Any ideas or suggestions to do that?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; When you create the plots, do this:&lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt; &amp;gt; p1 = plot(data1);&lt;br&gt;
&amp;gt; &amp;gt; set(p1,'tag','p1');&lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt; &amp;gt; Then if when you uncheck the box, do this:&lt;br&gt;
&amp;gt; &amp;gt; delete(findobj('tag','p1'))&lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt; &amp;gt; The tags allow you to find the objects and &quot;kill&quot; them.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Unless each of the plots takes a long time to calculate or render, I recommend&lt;br&gt;
&amp;gt; a slightly different approach for this situation. I suggest rendering each of the&lt;br&gt;
&amp;gt; plots at the start, each tagged uniquely; then when a particular plot is to show&lt;br&gt;
&amp;gt; up or not show up according to the state of the check box, you can just set&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; visstates = {'off', 'on'};&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thisisvis = visstates{1 + get(checkbox1, 'Value')};&lt;br&gt;
&amp;gt; set(findobj('tag','p1'), 'Visible', thisisvis) &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You don't even need any if/else statements for this logic.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt; .signature note: I am now avoiding replying to unclear or ambiguous postings.&lt;br&gt;
&amp;gt; Please review questions before posting them. Be specific. Use examples of what you mean,&lt;br&gt;
&amp;gt; of what you don't mean. Specify boundary conditions, and data classes and value&lt;br&gt;
&amp;gt; relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
/Linda</description>
    </item>
  </channel>
</rss>

