Fonction MATLAB qui imprime presque toutes les entrées
La fonction MATLAB suivante peut être utilisée pour imprimer chaque entrée en utilisant fprintf, indépendamment de son type. Puisqu’elle n’utilise pas mat2str(), elle peut également être utilisée dans la génération de code MATLAB Coder.
printit.m
function printit(inputValue)
if isnumeric(inputValue) || islogical(inputValue)
% Imprimer les tableaux numériques/logiques élément par élément
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