Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the next code

 Manipulate[
     Switch[x, a, If[selection =!= None, selection = None], b, 
        If[selection === None, selection = None], c, 
        If[selection === None, selection = "Hola"]
 ];
 selection, {x, {a, b, c}, ControlType -> PopupMenu},  
 {{selection, None}, 
     Switch[x, a, {"recta", "parabola"}, b, {"hiperbola", "absoluto"}, 
     c, {"Seno", "Coseno"}], ControlType -> PopupMenu}
 ]

but I need you to choose the second popupmenu I plot the function chosen.

share|improve this question
    
it seems to me that something's wrong with the second Switch statement there, could you clarify? (wrong number of arguments, the If doesn't quite make sense) –  Pinguin Dirk Sep 26 '13 at 19:17
    
Ok, I change the code, but I do not know where to put the Plot command for each that you can select the second PopUpMenu I plot the option chosen. –  Starlight Sep 26 '13 at 19:34

1 Answer 1

up vote 3 down vote accepted

Actually, I have to admit I do not quite understand what you are aiming for, so here's a long shot...

I understand that you want to have values in the second control (selection) that do depend on the first control, x that is.

Also, based on the title, I added some plots in the PopupMenu. Looks fun.

I hope it helps in some way. The key issue is that I introduced a helper, called selChoice to keep track of the updated selection-list. selChoice has ControlType None, so you won't see it in the actual Manipulate.

a = "Algebraicas";
b = "Trigonometricas";
c = "Tercer Grado";

Module[{myPlot},
    myPlot[f_] := Plot[f[x], {x, -5, 5}];
    Manipulate[
       Switch[x,
          a, If[selection =!= None, selection = None],
          b, If[selection === None, selection = None],
          c, If[selection === None, selection = "Hola"]];
       selection,
       {x, {a, b, c}, ControlType -> PopupMenu}, 
       {{selection, None}, selChoice, ControlType -> SetterBar},
       {{selChoice,
           Which[x == a, myPlot /@ {# &, #^2 &},
              x == b, myPlot /@ {#^3 &, Abs@# &},
              x == c, myPlot /@ {Sin, Cos}]}, None}]]

Note that I have no clue what you want to do with the first Switch... and also note that I am fully aware that my functions do not quite make sense in the respective categories.

Output:

enter image description here

EDIT

Based on the comment, maybe this is more what you want (I am still not sure)

Module[{myPlot}, myPlot[f_] := Plot[f[x], {x, -5, 5}];
  Manipulate[
    myPlot@selection, 
      {x, {a, b, c}, ControlType -> PopupMenu}, 
      {{selection, None}, selChoice, ControlType -> SetterBar}, 
      {{selChoice, Which[
         x == a, {# &, #^2 &}, 
         x == b, {#^3 &, Abs@# &}, 
         x == c, {Sin, Cos}]}, None}]]
share|improve this answer
    
It's similar to what I want but do not want to appear in the PopupMenu graphs, oh and another question Why the first PopUp control does not work? –  Starlight Sep 26 '13 at 19:49
    
The first selection does not show up as plot because of the Switch in the body of the Manipulate (no idea why you have it there). You can just remove that Switch. The remove the graphs from the popup, just don't Map myPlot on it. Please let me know if that is what you are after and I shall edit my answer (just wanna make sure I correctly understand) –  Pinguin Dirk Sep 26 '13 at 20:00
    
I don´t understand the question –  Starlight Oct 2 '13 at 14:56
    
@JennyOjeda: please see what I posted in the edit, let me know if this is what you want. I am afraid I also do have some problems understanding the "core" of the question –  Pinguin Dirk Oct 2 '13 at 15:16
    
Effectively what I want,Thank you :D , but as I am new to Mathematica I have many doubts about the symbols such as @ and & to be used? I looked at the list of special characters but I mathematica solves my doubt. –  Starlight Oct 2 '13 at 15:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.