I have defined the MATLAB class 'simpleClass' as shown below:
classdef simpleClass properties prop1 function_handle endend
When I create an instance of this class and try to assign a 'char' to 'prop1', as shown below, an error is thrown despite the fact that strings that are function names are convertible to function handles.
>> a = simpleClass>> a.prop1 = 'sin'Error setting property 'prop1' of class 'exampleClass':Invalid data type. Value must be function_handle or be convertible to function_handle.
However, the conversion below returns a valid function handle:
>> str2func('sin')ans = function_handle with value: @sin
Why is an error thrown when I try to set 'prop1' using a string?
Best Answer