-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrep2struct.m
More file actions
executable file
·37 lines (35 loc) · 1.01 KB
/
rep2struct.m
File metadata and controls
executable file
·37 lines (35 loc) · 1.01 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
function [varargout] = rep2struct(varargin)
% [s.target] = rep2struct(dat)
% replicate the value dat into each element of structure s in field target.
% if dat has same nb or elements as s, each element of dat goes into one
% element of s. if dat is more dimensional and doesn't have the same number
% of elements as s, and has same size along dimension 1, then pass each
% slice into s.target.
varargout = cell(1,nargout);
if numel(varargin) == 1
dat = varargin{1};
if numel(dat) == nargout
for i = 1:nargout
if iscell(dat(i))
varargout{i} = dat{i};
else
varargout{i} = dat(i);
end
end
elseif size(dat,1) == nargout
for i = 1:nargout
varargout{i} = dat(i,:);
end
else
for i = 1:nargout
varargout{i} = dat;
end
end
elseif numel(varargin) == nargout
for i = 1:nargout
varargout{i} = varargin{i};
end
else
error('Wrong number of arguments');
end
return