MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

More Efficient Use of Switch Statement

  • To: mathgroup at
  • Subject: [mg122764] More Efficient Use of Switch Statement
  • From: Darrel <dbarbato2 at>
  • Date: Thu, 10 Nov 2011 06:50:55 -0500 (EST)
  • Delivered-to:

Hi, As a beginner to Mathematica I have a question on whether there is
a more efficient way to do what I'm trying to do. I have something
similar to the following data:

dat = {{"BAD", "A", 2010, "October", "4 PM - 5 PM", 13},
{"BAD", "A", 2011, "April", "4 PM - 5 PM", 9},
{"BAD", "A", 2010, "December", "5 PM - 6 PM", 4},
{"BAD", "A", 2010, "October", "10 PM - 11 PM", 0},
{"BAD", "B", 2011, "October", "3 PM - 4 PM", 10},
{"BAD", "E", 2010, "April", "7 PM - 8 PM", 10},
{"BAD", "A", 2010, "October","Noon - 1 PM", 17},
{"BAD", "A", 2010, "October", "Noon - 1 PM",2},
{"BAD", "C", 2010, "July", "7 PM - 8 PM", 12},
{"GOOD", "A", 2010, "October", "5 PM - 6 PM", 5}}

I also have some manipulate code that looks like the following:

  {rating, year, month, type},
  {"All Ratings", "All Years", "All Months", "All Types"},
  Framed[forumData[[All, 6]]],
  {"All Ratings", "All Years", "All Months", _},
  Map[If[#[[2]] == type, Framed[#[[6]]], ""] &, forumData]
    *******(many more options)*****************
 {{rating, "All Ratings", "Rating"}, {"GOOD", "BAD", "All Ratings"},
ControlType -> PopupMenu},
 {{year, "All Years", "Year"}, {2010, 2011, "All Years"}, ControlType -
> PopupMenu},
 {{month, "All Months", "Month"}, {"January", "February", "March",
"April", "May", "June", "July", "August", "September", "October",
"November", "December", "All Months"}},
 {{type, "All Types", "Type"}, {"A", "B", "C", "D", "E", "All Types"}}

In reality, the code gets long fairly fast because I have even more
data than I have listed here that I want to have as options in the
manipulate. For most of the options I need this "All Types","All
Years",etc. selection to be an option for the user which leads to a
very messy and lengthy switch statement.
Is there a more efficient way of writing this code to avoid the
exhaustive approach, that I have here?

Thanks for the help.

  • Prev by Date: Re: Simulate and plot geometric brownian motion
  • Next by Date: Re: How to eliminate noises? A better way perhaps.
  • Previous by thread: References for ZipfDistribution and References in help pages in general
  • Next by thread: Re: Graphics << Implicit vs ContourPlot