How can i get value from field that created by uideditfiled command ?

18 Ansichten (letzte 30 Tage)
TARIK YAMAN
TARIK YAMAN am 14 Mär. 2021
Hi. I m new matlab app designer app. I create a numeric field and i ask input from user then i created automatically numeric field according to user input. (figure 2). How i can read values that where in created fields ?
Also, is there any different methods for creation fields automatically and adding as components.
classdef app8 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
NumEditFieldLabel matlab.ui.control.Label
NumEditField matlab.ui.control.NumericEditField
Button matlab.ui.control.Button
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
%% %% %% %% %% %% %% %% %% %% %% !!!!!!
function ButtonPushed(app, event)
for i = 1:app.NumEditField.Value
eval(sprintf('app8.ef%d = uieditfield(app.UIFigure,"numeric")',i));
eval(sprintf('app8.ef%d.Position = [180,350 - %d,31,22]',i,37*i))
end
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 NumEditFieldLabel
app.NumEditFieldLabel = uilabel(app.UIFigure);
app.NumEditFieldLabel.HorizontalAlignment = 'right';
app.NumEditFieldLabel.Position = [86 413 31 22];
app.NumEditFieldLabel.Text = 'Num';
% Create NumEditField
app.NumEditField = uieditfield(app.UIFigure, 'numeric');
app.NumEditField.Position = [132 413 100 22];
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [132 362 100 22];
% 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 = app8
% 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

Antworten (1)

Cameron B
Cameron B am 15 Mär. 2021
Are you just trying to get the value of the input from the user? If so then it's
YourNum = app.NumEditField.Value

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by