write a variant of fprintf

1 vue (au cours des 30 derniers jours)
Juan Cardelino
Juan Cardelino le 18 Avr 2012
Commenté : Andrew Janke le 31 Jan 2020
Dear all, I'm trying to implement a logging facility. For that reason, I want to replace my current calls fprintf(log_fid,"some label: %d\n, some_var) for something like myfprintf("some label: %d\n, some_var) and then call fprintf from within myprintf. My problem is that I don't know how to specificy the variable arguments list, I've tried like this:
function myfprintf(varargin)
fprintf(log_fid,varargin)
end
but that obviously won't work. Any suggestions? Thanks in advance. Best regards, Juan
  1 commentaire
Andrew Janke
Andrew Janke le 31 Jan 2020
Hey, if you're doing logging in Matlab, consider trying my SLF4M framework instead of rolling your own: https://github.com/apjanke/SLF4M

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 18 Avr 2012
function myfprintf(varargin)
fprintf(log_fid, varargin{:});
end
  1 commentaire
Juan Cardelino
Juan Cardelino le 18 Avr 2012
Thank you, a couple of hours after asking the question I realized myself that I forgot the {:}
It works nice.

Connectez-vous pour commenter.

Plus de réponses (2)

supriya
supriya le 18 Avr 2012
Try this one...
disp(sprintf('%d %d',log_fid,varargin));

supriya
supriya le 18 Avr 2012
else
fprintf('%d %d',log_fid,varargin);

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by