问题描述
我是新的 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 (将#修改为@)