write a variant of fprintf

조회 수: 4 (최근 30일)
Juan Cardelino
Juan Cardelino 2012년 4월 18일
댓글: Andrew Janke 2020년 1월 31일
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
Andrew Janke
Andrew Janke 2020년 1월 31일
Hey, if you're doing logging in Matlab, consider trying my SLF4M framework instead of rolling your own: https://github.com/apjanke/SLF4M

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 4월 18일
function myfprintf(varargin)
fprintf(log_fid, varargin{:});
end
  댓글 수: 1
Juan Cardelino
Juan Cardelino 2012년 4월 18일
Thank you, a couple of hours after asking the question I realized myself that I forgot the {:}
It works nice.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

supriya
supriya 2012년 4월 18일
Try this one...
disp(sprintf('%d %d',log_fid,varargin));

supriya
supriya 2012년 4월 18일
else
fprintf('%d %d',log_fid,varargin);

카테고리

Help CenterFile Exchange에서 Exponents and Logarithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by