I\'m looking for a function in Matlab to use for error messages, like so:
error([\'Invalid value for someVariable: \' wantedFunction(someVariable)]);
No, there is no such function. I ran into similar problems, so here is a very rudimentary function that I use. Do realize that it is not complete. For example, it does not output fields of a structure in a meaningful way, but that can easily be added. You can treat it as a base implementation and fit it to your needs.
function ret = all2str(param)
if isempty(param)
if iscell(param)
ret = '(empty cell)';
elseif isstruct(param);
ret = '(empty struct)';
else
ret = '(empty)';
end
return;
end
if ischar(param)
ret = param;
return;
end
if isnumeric(param)
ret = num2str(param);
return;
end
if iscell(param)
ret = all2str(param{1});
for i=2:numel(param)
ret = [ret ', ' all2str(param{i})];
end
return;
end
if isstruct(param)
ret = '(structure)';
return;
end
end