I am trying to use the one button to assign to two variables. Here is an example of how I want it to work.
expression:
"Magnitude = ", mstar, ", Distance = ", dstar,
sliders:
"Magnitude:", {{mstar, mSun, "Magnitude"}, mSun, 30},
"Distance:", {{dstar, dSun, "Distance"}, dSun, 600},
buttons:
"or Select Star:",
{{mstar&&dstar, mAltair&&dAltair, "Star"},
{mAltair&&dAltair -> "Altair", mCanopus&&dCanopus -> "Canopus",
mEpisilonIndi&&dEpisilonIndi -> "Episilon Indi"},
ControlType -> Setter}
In this example, it would work fine if it was able to assign both variables when pressing the desired button, however &&
doesn't work like this. My only solution is to have a button for each variable;
"or Select Star:",
{{mstar, mAltair, "Subscript[Star, m]"},
{mAltair -> "Altair", mCanopus -> "Canopus", mEpisilonIndi -> "Episilon Indi"},
ControlType -> Setter},
"or Select Star:",
{{dstar, mAltair, "Subscript[Star, d]"},
{dAltair -> "Altair", dCanopus -> "Canopus", dEpisilonIndi -> "Episilon Indi"},
ControlType -> Setter}
However, this requires me to press both buttons, where my desired effect is to only have to press one. Is there a way I can achieve this?, I am aware that I can assign a variable two values such as;
Sun = {mSun, dSun}
I don't know the correct expression or even if it's possible. Can I do this and have my expression able to choose which value to use? Like this?
"Magnitude = ", star{value1}, ", Distance = ", star{value2},
"Magnitude:", {{star{value1}, Sun{value1}, "Magnitude"}, Sun{value1}, 30},
"Distance:", {{star{value2}, Sun{Value2}, "Distance"}, Sun{value1}, 600},
"or Select Star:",
{{star, Sun, "Star"},
{Altair -> "Altair", Canopus -> "Canopus", EpisilonIndi -> "Episilon Indi"},
ControlType -> Setter}
Edit
This is the current coding which displays the first image:
Manipulate[
Column[{Row[{"Apparent magnitude = ", mstar, ", distance = ", dstar, "pc"}], Style[Row[{"Star has Absolute Magnitude of ", mstar - 5 ((Log10[dstar]) - 1)}], Bold, 24]}, Spacings -> {0, 1.5}],
"Choose apparent magnitude:", {{mstar, mSun, "m"}, mSun, 30},
"choose distance:", {{dstar, dSun, "d"}, dSun, 600},
"or select desired star:",
{{mstar, mSun, "m"}, {mAltair -> "Altair", mCanopus -> "Canopus", mEpisilonIndi -> "Episilon Indi", mRigel -> "Rigel", mProximaCentauri -> "Proxima Centauri", mSun -> "Sun", mZetaOphiuchi -> "Zeta Ophiuchi"}, ControlType -> Setter},
{{dstar, dSun, "d"}, {dAltair -> "Altair", dCanopus -> "Canopus", dEpisilonIndi -> "Episilon Indi", dRigel -> "Rigel", dProximaCentauri -> "Proxima Centauri", dSun -> "Sun", dZetaOphiuchi -> "Zeta Ophiuchi"}, ControlType -> Setter}]
This is an example of how I want it to be displayed by being able to use a single button to assign both variables. The coding in this second image is a little different using Switch functions for the two variables, however a third variable is required for the actual Switch. I believe this would benefit from being able to assign two individual values to one variable, otherwise the sliders still require two individual variables.
Here is the coding of the two variable switches:
Switch[star, Altair, mRigel, Canopus, mCanopus, EpisilonIndi, mEpisilonIndi, Rigel, mRigel, ProximaCentauri, mProximaCentauri, Sun, mSun, ZetaOphiuchi, mZetaOphiuchi]
Switch[star, Altair, dRigel, Canopus, dCanopus, EpisilonIndi, dEpisilonIndi, Rigel, dRigel, ProximaCentauri, dProximaCentauri, Sun, dSun, ZetaOphiuchi, dZetaOphiuchi]
Here is the coding of the buttons:
{{star, Altair, "s"}, {Altair -> "Altair", Canopus -> "Canopus", EpisilonIndi -> "Episilon Indi", Rigel -> "Rigel", ProximaCentauri -> "Proxima Centauri", Sun -> "Sun", ZetaOphiuchi -> "Zeta Ophiuchi"}, ControlType -> Setter}
As there is now a single variable, star
, which assigns the other two, mstar
and dstar
, the sliders require use of the same variable. A Switch
cannot be placed where the star
variable is as it's an invalid parameter.
"Choose apparent magnitude:", {{star, mSun, "m"}, mSun, 30},
"Choose distance:", {{star, dSun, "d"}, dSun, 600},
Hopefully this makes a more sense, I am very new to Mathematica and have only been using it for about a week.
Edit 2
I adjusted the project to substitute the previous buttons with actual Button
functions, it works flawlessly. The following image is how the new output is displayed:
The buttons are now using the following code:
Button["Altair", mstar = mAltair; dstar = dAltair]
Manipulate
, aren't they? I'm not sure if I understand your problem but can't you justButton["label", v1=2;v2=5;]
? $\endgroup$Button
. $\endgroup$