I'm not going to comment on the wisdom of using evalin.
The problem is not with cellfun. You'll get the same error if you do:
val = evalin('base', '');
The error message could be better as it looks like you're seeing an implementation detail of evalin, but clearly, '' is not allowed as an input for evalin.
The workaround would be to create your own wrapper that catches errors with evalin (would also help if the variable name you pass is not actually a variable):
function value = evalin_with_catch(varname)
try
value = evalin('base', varname)
catch
value = 'INVALID VARIABLE';
end
end
then:
X_values = cellfun(@evalin_with_catch, C, 'UniformOutput', false);
Best Answer