MATLAB function which prints almost every input
The following MATLAB function can be used to print every input using fprintf, independent of its type. Since it doesn’t use mat2str(), it can also be used in MATLAB Coder code generation.
printit.m
function printit(inputValue)
if isnumeric(inputValue) || islogical(inputValue)
% Print numeric/logical arrays element-wise
fprintf('Input: %g \n', inputValue(:));
elseif ischar(inputValue)
fprintf('Input: %s\n', inputValue);
elseif isstring(inputValue)
fprintf('Input: %s\n', char(inputValue));
elseif iscell(inputValue)
disp('Input (cell):');
disp(inputValue);
elseif isstruct(inputValue)
disp('Input (struct):');
disp(inputValue);
else
disp('Input (unknown type):');
disp(inputValue);
end
endCheck out similar posts by category:
Matlab/Simulink
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow