How to require a custom class type with addRequired?
Mostrar comentarios más antiguos
I have a custom class,
classdef foo
properties
%Property stuff
prop1;
end
methods
function obj = foo( )
%Constructor stuff.
obj.prop1 = 'test';
end
end
end
and I want the input of a function to require that the variable type is this custom class.
function out = fun( varargin )
p = inputParser;
addRequired( p, 'InputName', @(x) isa( x, 'foo' ) );
parse( p, varargin{:} );
% Function stuff
end
When I try doing this
% Script.
objInstance = foo();
out = fun( 'InputName', objInstance )
I get this error:
" The value of 'InputName' is invalid. It must satisfy the function: @(x)isa(x,'foo'). "
Respuesta aceptada
Más respuestas (1)
Luna
el 5 de Dic. de 2019
0 votos
Variable out is not defined in the function bar. Also bar is already a built-in function. Use another function name instead.
1 comentario
Dominik Mattioli
el 5 de Dic. de 2019
Categorías
Más información sobre Argument Definitions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!