MATLAB es un entorno informático basado en arrays con su propio lenguaje de programación que es fácil de aprender y usar. Con la ayuda de la interfaz gráfica de usuario GUI de MATLAB, se utiliza para comprender ideas matemáticas complejas y grandes conjuntos de datos.
Los cuadros de lista son elementos de la interfaz de usuario que muestran los elementos de una lista. La apariencia y el comportamiento de un cuadro de lista están controlados por sus propiedades. Para referirse a un objeto o propiedad específica.
Ejemplo 1:
Matlab
% MATLAB Code function dataselectionbox fig = uifigure('Position',[200 200 650 475]); % Making a Numeric Edit Field ef = uieditfield(fig,'numeric',... 'Position',[250 180 200 44]); % Making a List Box lbox = uilistbox(fig,... 'Items', {'GFG1', 'GFG2', 'GFG3', 'GFG3'},... 'ItemsData', [0, 25, 40, 100],... 'Position',[250 240 200 156],... 'ValueChangedFcn'); % Callback to a function that has had its value changed function selectionChanged(src,event) % In the edit field, show the data from the list box. ef.Value = src.Value; end end
Producción:
Seleccione un elemento de la lista con selección de datos. La temperatura vinculada con la selección se actualiza en el cuadro de edición numérico.
Ahora vemos la aplicación basada en GUI de ListBox en MATLAB. Para ello seleccionamos la opción Design App con la opción ListBox en MATLAB.
Ejemplo 2:
Matlab
% MATLAB code for ListBox GUI classdef appList < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure ListBoxGUIdemoLabel matlab.ui.control.Label EditField3 matlab.ui.control.NumericEditField ResultLabel matlab.ui.control.Label EnterSecondNumberLabel matlab.ui.control.Label EnterFirstNumberLabel matlab.ui.control.Label EditField2 matlab.ui.control.EditField EditField matlab.ui.control.EditField ListListBox matlab.ui.control.ListBox ListListBoxLabel matlab.ui.control.Label end % Callbacks that handle component events methods (Access = private) % Callback function function CSESubjectListBoxValueChanged(app, event) end % Value changed function: ListListBox function List1.ListBoxValueChanged(app, event) value = app.List1.ListBox.Value; value = get(handles.ListBox,'value'); A Label = get(handles.edit1.'String'); B label = get(handles.edit1.'String'); A Label = Str2num(A); B Label = Str2num(B); end end % Component initialization methods (Access = private) % Create UIFigure and components function createComponents(app) % Create UIFigure and hide until all components are created app.UIFigure = uifigure('Visible', 'off'); app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'MATLAB App'; % Create ListListBoxLabel app.ListListBoxLabel = uilabel(app.UIFigure); app.ListListBoxLabel.HorizontalAlignment = 'right'; app.ListListBoxLabel.Position = [73 178 48 22]; app.ListListBoxLabel.Text = 'List '; % Create ListListBox app.ListListBox = uilistbox(app.UIFigure); app.ListListBox.Items = {'Add', 'Sub', 'Multiply', 'Division'}; app.ListListBox.ValueChangedFcn = createCallbackFcn(app, @ListListBoxValueChanged, true); app.ListListBox.Position = [186 63 284 149]; app.ListListBox.Value = 'Add'; % Create EditField app.EditField = uieditfield(app.UIFigure, 'text'); app.EditField.Position = [307 356 163 45]; % Create EditField2 app.EditField2 = uieditfield(app.UIFigure, 'text'); app.EditField2.Position = [307 303 163 44]; % Create EnterFirstNumberLabel app.EnterFirstNumberLabel = uilabel(app.UIFigure); app.EnterFirstNumberLabel.Position = [73 356 156 45]; app.EnterFirstNumberLabel.Text = 'Enter First Number'; % Create EnterSecondNumberLabel app.EnterSecondNumberLabel = uilabel(app.UIFigure); app.EnterSecondNumberLabel.Position = [71 303 132 44]; app.EnterSecondNumberLabel.Text = 'Enter Second Number'; % Create ResultLabel app.ResultLabel = uilabel(app.UIFigure); app.ResultLabel.Position = [73 242 178 36]; app.ResultLabel.Text = 'Result'; % Create EditField3 app.EditField3 = uieditfield(app.UIFigure, 'numeric'); app.EditField3.Position = [307 231 163 43]; % Create ListBoxGUIdemoLabel app.ListBoxGUIdemoLabel = uilabel(app.UIFigure); app.ListBoxGUIdemoLabel.BackgroundColor = [0.3922 0.8314 0.0745]; app.ListBoxGUIdemoLabel.FontWeight = 'bold'; app.ListBoxGUIdemoLabel.Position = [71 426 420 33]; app.ListBoxGUIdemoLabel.Text = 'List Box GUI demo'; % Show the figure after all components are created app.UIFigure.Visible = 'on'; end end % App creation and deletion methods (Access = public) % Construct app function app = appList % Create UIFigure and components createComponents(app) % Register the app with App Designer registerApp(app, app.UIFigure) if nargout == 0 clear app end end % Code that executes before app deletion function delete(app) % Delete UIFigure when app is deleted delete(app.UIFigure) end end end
Producción: