Defining an array dependant on multiple user inputs

1 visualización (últimos 30 días)
Ashton Linney
Ashton Linney el 15 de Abr. de 2020
Respondida: Mehmed Saad el 16 de Abr. de 2020
For this example, I have 2 independant modes, where each mode can be in state A, B, C or D, giving 16 possible combinations in this specific order:
AA,BA,AB,BB,CA,CB,AC,BC,CC,DA,DB,DC,AD,BD,CD,DD
And they each correspond to elements in a 1 by 16 array respectively. This 1 by 16 array represents the initial state which will be put into an ODE solver. For example, if the initial state is CA, the array will be [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].
The input method for the user to decide this initial state will be two drop down lists, one for each mode, and each drop down box will have the options to select state A, B, C or D for that mode. Therefore, through the two drop down lists, all 16 combinations can be achieved, but only one can be selected at a single time.
How can I generate the 1 by 16 array automatically depending on which combination of states the user inputs?
Thank you

Respuestas (1)

Mehmed Saad
Mehmed Saad el 16 de Abr. de 2020
1. Using Livescript
Menu1 = "A";%these are drop down menu from live script
Menu2 = "A";%these are drop down menu from live script
x = split('AA,BA,AB,BB,CA,CB,AC,BC,CC,DA,DB,DC,AD,BD,CD,DD',',');
val1 = strcat(Menu1,Menu2);
init_array = 1*strcmp(x,val1)'
2. Using UI
global val1 val2
val2 =0;
select_dropdown;
while(val2~=1)
pause(0.1);
end
x = split('AA,BA,AB,BB,CA,CB,AC,BC,CC,DA,DB,DC,AD,BD,CD,DD',',');
init_array = 1*strcmp(x,val1)'
function select_dropdown
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [ 735 530 431 140];
app.UIFigure.Name = 'UI Figure';
% Create Menu1DropDownLabel
app.Menu1DropDownLabel = uilabel(app.UIFigure);
app.Menu1DropDownLabel.HorizontalAlignment = 'right';
app.Menu1DropDownLabel.Position = [34 100 46 22];
app.Menu1DropDownLabel.Text = 'Menu-1';
% Create Menu1DropDown
app.Menu1DropDown = uidropdown(app.UIFigure);
app.Menu1DropDown.Items = {'A', 'B', 'C', 'D'};
app.Menu1DropDown.Position = [95 100 100 22];
app.Menu1DropDown.Value = 'A';
% Create Menu1DropDown_2Label
app.Menu1DropDown_2Label = uilabel(app.UIFigure);
app.Menu1DropDown_2Label.HorizontalAlignment = 'right';
app.Menu1DropDown_2Label.Position = [240 100 46 22];
app.Menu1DropDown_2Label.Text = 'Menu-1';
% Create Menu1DropDown_2
app.Menu1DropDown_2 = uidropdown(app.UIFigure);
app.Menu1DropDown_2.Items = {'A', 'B', 'C', 'D'};
app.Menu1DropDown_2.Position = [301 100 100 22];
app.Menu1DropDown_2.Value = 'A';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
app.Done_button = uibutton(app.UIFigure,'push');
%%
app.Done_button.Position = [180 40 100 22];
app.Done_button.Text = 'Done';
app.Done_button.ButtonPushedFcn = @flafa;
end
function flafa(a,~)
global val1 val2;
val1 = [a.Parent.Children(2).Value a.Parent.Children(4).Value];
close(a.Parent);
val2 = 1;
end

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by