打印几乎每个输入的 MATLAB 函数
以下 MATLAB 函数可用于使用 fprintf 打印每个输入,无论其类型如何。由于它不使用 mat2str(),因此也可以在 MATLAB Coder 代码生成中使用。
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
end按类别查看类似文章:
MATLAB/Simulink
如果这篇文章对您有帮助,请考虑请我喝杯咖啡或通过 PayPal 捐款,以支持 TechOverflow 上新文章的研究与发布