您需要初始化villes1
为gobjects
.
请参阅图形数组。
例子:
properties (Access = private)
GHIetPOA_grid matlab.ui.container.GridLayout
villes1 = gobjects(1, 8);
end
我只能猜测您使用了以下语法:上述语法创建了一个元素villes1 = zeros(1, 8);
数组。
然后创建一个“旧式”数字句柄,而不是创建一个对象。
使用数字句柄时禁止点表示法。 double
app.villes1(i) = uieditfield(...)
您需要改用以下语法:villes1 = gobjects(1, 8);
.
现在点索引应该可以工作了。
这是完整的代码(包括生成的代码):
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
end
properties (Access = private)
Panel matlab.ui.container.Panel
GHIetPOA_grid matlab.ui.container.GridLayout
villes1 = gobjects(1, 8);
end
methods (Access = private)
function initVilles1(app)
for i=1:8
app.villes1(i) = uieditfield(app.GHIetPOA_grid, 'text', 'HorizontalAlignment', ...
'center', 'Editable', 'on');
app.villes1(i).Layout.Row = 2;
app.villes1(i).Layout.Column = i+2;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Create Panel
app.Panel = uipanel(app.UIFigure);
app.Panel.Title = 'Panel';
app.Panel.Position = [42 198 1026 464];
% Create GridLayout
app.GHIetPOA_grid = uigridlayout(app.Panel);
app.GHIetPOA_grid.RowHeight = {'1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x'};
%app.villes1 = uieditfield(app.GHIetPOA_grid, 'text', 'HorizontalAlignment', 'center', 'Editable', 'on');
initVilles1(app);
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 1118 692];
app.UIFigure.Name = 'UI Figure';
% 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 = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
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
备注:下次发问题时,请尽量贴出所有相关代码。