How to develop a number selector using matlab app designer?

2 vues (au cours des 30 derniers jours)
CalebJones
CalebJones le 11 Nov 2019
classdef tutorialApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
Button_2 matlab.ui.control.Button
Button_3 matlab.ui.control.Button
Button_4 matlab.ui.control.Button
Button_5 matlab.ui.control.Button
Button_6 matlab.ui.control.Button
Button_7 matlab.ui.control.Button
Button_8 matlab.ui.control.Button
Button_9 matlab.ui.control.Button
Button_10 matlab.ui.control.Button
RealTimefNIRSNumberSelectorLabel matlab.ui.control.Label
SelectedNumberLabel matlab.ui.control.Label
SelectedNumberTextArea matlab.ui.control.TextArea
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 495 262];
app.UIFigure.Name = 'UI Figure';
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.Position = [18 138 43 22];
app.Button.Text = '1';
% Create Button_2
app.Button_2 = uibutton(app.UIFigure, 'push');
app.Button_2.Position = [60 138 43 22];
app.Button_2.Text = '2';
% Create Button_3
app.Button_3 = uibutton(app.UIFigure, 'push');
app.Button_3.Position = [111 138 43 22];
app.Button_3.Text = '3';
% Create Button_4
app.Button_4 = uibutton(app.UIFigure, 'push');
app.Button_4.Position = [153 138 43 22];
app.Button_4.Text = '4';
% Create Button_5
app.Button_5 = uibutton(app.UIFigure, 'push');
app.Button_5.Position = [205 138 43 22];
app.Button_5.Text = '5';
% Create Button_6
app.Button_6 = uibutton(app.UIFigure, 'push');
app.Button_6.Position = [247 138 43 22];
app.Button_6.Text = '6';
% Create Button_7
app.Button_7 = uibutton(app.UIFigure, 'push');
app.Button_7.Position = [300 138 43 22];
app.Button_7.Text = '7';
% Create Button_8
app.Button_8 = uibutton(app.UIFigure, 'push');
app.Button_8.Position = [342 138 43 22];
app.Button_8.Text = '8';
% Create Button_9
app.Button_9 = uibutton(app.UIFigure, 'push');
app.Button_9.Position = [402 138 43 22];
app.Button_9.Text = '9';
% Create Button_10
app.Button_10 = uibutton(app.UIFigure, 'push');
app.Button_10.Position = [444 138 43 22];
app.Button_10.Text = '0';
% Create RealTimefNIRSNumberSelectorLabel
app.RealTimefNIRSNumberSelectorLabel = uilabel(app.UIFigure);
app.RealTimefNIRSNumberSelectorLabel.FontName = 'Javanese Text';
app.RealTimefNIRSNumberSelectorLabel.FontWeight = 'bold';
app.RealTimefNIRSNumberSelectorLabel.FontColor = [0 0 1];
app.RealTimefNIRSNumberSelectorLabel.Position = [144 213 192 28];
app.RealTimefNIRSNumberSelectorLabel.Text = 'Real Time fNIRS Number Selector';
% Create SelectedNumberLabel
app.SelectedNumberLabel = uilabel(app.UIFigure);
app.SelectedNumberLabel.HorizontalAlignment = 'right';
app.SelectedNumberLabel.Position = [98 63 102 22];
app.SelectedNumberLabel.Text = 'Selected Number:';
% Create SelectedNumberTextArea
app.SelectedNumberTextArea = uitextarea(app.UIFigure);
app.SelectedNumberTextArea.Position = [215 44 150 60];
% 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 = tutorialApp
% 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
Every time I select a button it should display that number in a textarea.

Réponses (2)

Steven Lord
Steven Lord le 11 Nov 2019
Do you need individual buttons for each digit, or would a uispinner or uidropdown that allows you to select a number between 0 and 9 be sufficient?
  1 commentaire
CalebJones
CalebJones le 12 Nov 2019
Modifié(e) : CalebJones le 12 Nov 2019
No I need a buttons only. The application requires that.

Connectez-vous pour commenter.


Abhinav
Abhinav le 5 Juil 2023
If you need buttons only, have a property as follows
properties (Access = private)
Number % Description
end
Then just have callbacks to all your buttons so that OnClick Number gets assigned the button value.
Then just set your text box value to Number
app.TextArea.Value = Number;
or you could directly set app.TextArea.Value to number in the callbacks

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by