forked from petercorke/robotics-toolbox-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multidfprintf.m
61 lines (57 loc) · 2.08 KB
/
multidfprintf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
%MULTIDFPRINTF Print formatted text to multiple streams
%
% COUNT = MULTIDFPRINTF(IDVEC, FORMAT, A, ...) performs formatted output
% to multiple streams such as console and files. FORMAT is the format string
% as used by sprintf and fprintf. A is the array of elements, to which the
% format will be applied similar to sprintf and fprint.
%
% IDVEC is a vector (1xN) of file descriptors and COUNT is a vector (1xN) of
% the number of bytes written to each file.
%
% Notes::
% - To write to the consolde use the file identifier 1.
%
% Example::
% % Create and open a new example file:
% fid = fopen('exampleFile.txt','w+');
% % Write something to the file and the console simultaneously:
% multidfprintf([1 FID],'% s % d % d % d!\n','This is a test!',1,2,3);
% % Close the file:
% fclose(FID);
%
% Authors::
% Joern Malzahn, ([email protected])
%
% See also fprintf,sprintf.
% Copyright (C) 1993-2014, by Peter I. Corke
%
% This file is part of The Robotics Toolbox for MATLAB (RTB).
%
% RTB is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RTB is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with RTB. If not, see <http://www.gnu.org/licenses/>.
%
% http://www.petercorke.com
function [count] = multidfprintf(idVec,varargin)
if isempty(idVec)
warning('multIDFprintf','Target ID is empty. Nothing is written.')
count = [];
else
count = zeros(size(idVec));
for iID = 1:numel(idVec)
if idVec(iID) < 1
count(iID) = 0;
else
count(iID) = fprintf(idVec(iID),varargin{:});
end
end
end