Is there a way to select a variable from a drown down menu rather than a string?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Eddie Martin
el 5 de Ag. de 2020
Editada: Eddie Martin
el 5 de Ag. de 2020
I want to have something like this:
x = 1;
y = 2;
z = 3;
% drop down menu options are x, y, or z.
dropdownValue = x;
disp(dropdownValue);
dropdownValue
= 1
what I actually get is:
x = 1;
y = 2;
z = 3;
% drop down menu options are x, y, or z.
dropdownValue = 'x';
disp(dropdownValue);
dropdownValue
= x
I'm struggling to describe it very well but hope this kind of sudo-code helps!
0 comentarios
Respuesta aceptada
Walter Roberson
el 5 de Ag. de 2020
var_values = [x; y; z];
dropdownIDX = handles.AppropriateHandleName.Value;
dropdownValue = var_values(dropdownIDX);
That is, the Value property of a uicontrol 'style', 'drop' is the index of the selected entry. You would use that index to index into the list of values to get the selected value.
You would not use dynamic variable names.
However, you could also use
var_values.x = x; var_values.y = y; var_values.z = z;
dropdownEntries = handles.AppropriateHandleName.String;
dropdownIDX = handles.AppropriateHandleName.Value;
dropDownString = dropdownEntries{dropdownIDX}; %this is the part that would get you 'x'
dropdownValue = var_values.(dropDownString);
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!