Configure for app fails with "Too many input arguments" when component has an empty constructor
22 次查看(过去 30 天)
显示 更早的评论
I created the default custome component in the appdesigner. Added an empty constructor and tried to "configure for apps". If fails with "Too many input arguments". I tried adding if nargin > 0, end; Still get the error.
classdef comp1 < matlab.ui.componentcontainer.ComponentContainer
% Properties that correspond to underlying components
properties (Access = private, Transient, NonCopyable)
end
methods
%ctor - if I remove this, I can register without errors
function comp = comp1
end
end
methods (Access = protected)
% Code that executes when the value of a public property is changed
function update(comp)
% Use this function to update the underlying components
end
% Create the underlying components
function setup(comp)
comp.Position = [1 1 320 240];
comp.BackgroundColor = [0.94 0.94 0.94];
end
end
end
0 个评论
回答(1 个)
Lokesh
2024-10-28,20:37
Hello Mark,
I understand that you are experiencing "Too many input arguments" error when trying to configure your custom component in App Designer.
This issue arises because the constructor in the custom component class is not handling input arguments properly.
The constructor should be designed to accept a variable number of input arguments using 'varargin'. This ensures that it can handle any arguments MATLAB might pass during the configuration process. Here's a modified version of the class:
classdef comp1 < matlab.ui.componentcontainer.ComponentContainer
% Properties that correspond to underlying components
properties (Access = private, Transient, NonCopyable)
end
methods
% Constructor - handle variable input arguments
function comp = comp1(varargin)
if nargin > 0
% Handle constructor input arguments if necessary
% Example: Set properties based on input arguments
end
end
end
methods (Access = protected)
% Code that executes when the value of a public property is changed
function update(comp)
% Use this function to update the underlying components
end
% Create the underlying components
function setup(comp)
comp.Position = [1 1 320 240];
comp.BackgroundColor = [0.94 0.94 0.94];
end
end
end
By using 'varargin', the constructor can now accept any number of arguments, preventing the "Too many input arguments" error during registration. This approach maintains flexibility in handling inputs as needed.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Custom UI Components 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!