如何解决如何从 uideditfiled 命令创建的字段中获取值?
我是新的 matlab 应用程序设计器应用程序。我创建了一个数字字段,然后我要求用户输入,然后我根据用户输入自动创建数字字段。 (图2)。我如何读取创建字段中的值? 另外,是否有不同的方法可以自动创建字段并作为组件添加。
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
结束
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。