Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8991

Re: Dynamically create Select criteria

From Jack McInerney <ejmcinerney@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Dynamically create Select criteria
Date 2012-03-13 08:06 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jjmv5r$chm$1@smc.vnet.net> (permalink)
References <201203091110.GAA26899@smc.vnet.net> <jjkek8$1cb$1@smc.vnet.net>

Show all headers | View raw


On Mar 12, 2:11 am, Bob Hanlon <hanlonr...@gmail.com> wrote:
> data = {
>    {"Fido", "dog", 8},
>    {"Sparky", "dog", 2},
>    {"Shadow", "cat", 1},
>    {"Cuddles", "cat", 3},
>    {"Cutey", "rabbit", 1}};
>
> types = Union[data[[All, 2]]];
>
> ages = Union[data[[All, 3]]];
>
> Manipulate[selection = Select[data,
>    (age != {} || type != {}) &&
>      (age != {} && type == {} ||
>        MemberQ[type, #[[2]]]) &&
>      (type != {} && age == {} ||
>        MemberQ[age, #[[3]]]) &],
>  {{type, {}, Style["Type", Blue, 12]}, types},
>  {{age, {}, Style["Age", Blue, 12]}, ages},
>  ControlType -> CheckboxBar]
>
> Dynamic[selection]
>
> Bob Hanlon
>
>
>
> On Fri, Mar 9, 2012 at 6:10 AM, Jack McInerney <ejmciner...@gmail.com> wrote:
> > I have a database in the form of a big list, and want to select a
> > subset of this list, by allowing the user to click on checkboxes.  The
> > example below shows the idea.  Given a list of animals, lets say I
> > want to select all the cats that are 1 year old, or all of the dogs
> > and cats.  I can't figure out how to use the output of my checkboxes
> > to dynamically create a selection criteria for the Select function.
> > Is this possible?  Any thoughts would be appreciated.
>
> > data={{"fido", "dog",8},
> > {"Sparky", "dog",2},
> > {"Shadow", "cat",1},
> > {"Cuddles", "cat",3},
> > {"Cutey", "rabbit",1}};
>
> > CheckboxBar[Dynamic[type], DeleteDuplicates[data[[All,2]] ]]
>
> > CheckboxBar[Dynamic[age], Sort[DeleteDuplicates[data[[All,3]] ]]]
>
> > Dynamic[Select[data, #[[2]]==type[[1]] && #[[3]]==age[[1]]&]] (*<--
> > criteria should depend on which boxes have been checked by user *)
>
> > Thanks,
> > Jack- Hide quoted text -
>
> - Show quoted text -

Hi Bob,

This is an amazing piece of Mathematica code you produced.  It works
perfectly, but I have only a partial grasp on how it works.  I will
need to study it some more.  A lot more...

Jack

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Dynamically create Select criteria Bob Hanlon <hanlonr357@gmail.com> - 2012-03-12 09:11 +0000
  Re: Dynamically create Select criteria Jack McInerney <ejmcinerney@gmail.com> - 2012-03-13 08:06 +0000

csiph-web