-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcellprintf.m
More file actions
executable file
·50 lines (46 loc) · 1.12 KB
/
cellprintf.m
File metadata and controls
executable file
·50 lines (46 loc) · 1.12 KB
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
%CELLPRINTF Write formatted data to cell array
%
% S = CELLPRINTF(FORMAT,V1,V2,...)
%
% INPUT
% FORMAT String encoding the format of text
% V1,V2,... Vector(s) containing values to filled in FORMAT
%
% OUTPUT
% S Cell array of strings
%
% DESCRIPTION
% Create text strings in a cell array, using format FORMAT. The string
% FORMAT is the same as is used in fprintf or sprintf. The next input
% arguments are vector inputs that are filled in FORMAT.
% An example:
% >> cellprintf('Hallo %d, %d',1:5, [3 5 4 8 5])
% ans =
% 'Hallo 1, 3'
% 'Hallo 2, 5'
% 'Hallo 3, 4'
% 'Hallo 4, 8'
% 'Hallo 5, 5'
%
% SEE ALSO
% fprintf, sprintf, getwnames
% Copyright: D.M.J. Tax, D.M.J.Tax@prtools.org
% Faculty of Applied Physics, Delft University of Technology
% P.O. Box 5046, 2600 GA Delft, The Netherlands
function s = cellprintf(str,varargin)
N = length(varargin);
nr = length(varargin{1});
for i=2:N
if length(varargin{i})~=nr
error('All input arguments have to have equal length.');
end
end
s = cell(nr,1);
for i=1:nr
in = cell(N,1);
for j=1:N
in{j} = varargin{j}(i);
end
s{i} = sprintf(str,in{:});
end
return