MATLAB-Funktion, die fast jede Eingabe ausgibt
Die folgende MATLAB-Funktion kann verwendet werden, um jede Eingabe mit fprintf auszugeben, unabhängig von ihrem Typ. Da sie nicht mat2str() verwendet, kann sie auch in der MATLAB-Coder-Codegenerierung verwendet werden.
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