/usr/share/psychtoolbox-3/PsychOneliners/Interleave.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 62 63 64 65 66 | function [vec] = Interleave(varargin)
% [vec] = Interleave(varargin)
% Interleaves any number of vectors and scalars
% input is taken from consequetive elements of each input variable until a
% variable runs out.
% Output will be a columnvector.
% Output will be cell if any of the inputs is cell.
% Output will be char if none of the input is cell and any of the inputs is
% char
%
% a = [A A A], b= [B B], c= [C C C C], d=D
% out = Interleave(a,b,c,d)
% out = [A B C D A B C A C C];
%
% DN 06-11-2007
% DN 23-01-2008 updated to support scalars and conversion to char
% DN 28-04-2008 simplified input checking
% DN 28-05-2008 bugfix mixing numeric and char
% DN 09-06-2011 Now works fine with empty inputs. Few changes for compatibility
% with Octave, might have more up ahead.
% remove empties
varargin(cellfun(@isempty,varargin)) = [];
% check if we have any input
if isempty(varargin)
vec = [];
return;
end
% we have work to do, first some other input checks
for p=1:length(varargin) % cannot use nargin as we just possibly deleted input arguments
psychassert(isvector(varargin{p}) || isscalar(varargin{p}),'not all inputs are vectors or scalars');
psychassert(isnumeric(varargin{p}) || iscell(varargin{p}) || ischar(varargin{p}),'not all inputs are numeric, cell or char')
end
% remove empty inputs
qEmpty = cellfun(@isempty,varargin);
varargin(qEmpty) = [];
% check what input we have
qchar = any(cellfun(@ischar,varargin));
qcell = any(cellfun(@iscell,varargin));
qnum = cellfun(@isnumeric,varargin);
if any(qnum) && qchar && ~qcell
% convert all numeric inputs to char
inds = find(qnum);
for p=1:length(inds)
temp = num2cell(varargin{inds(p)});
varargin{inds(p)} = cellfun(@num2str,temp,'UniformOutput',false);
end
% pack all other inputs in cell as well for Octave
inds = find(~qnum);
for p=1:length(inds)
varargin{inds(p)} = num2cell(varargin{inds(p)});
end
end
for p=1:numel(varargin)
r(p,1:numel(varargin{p})) = num2cell(varargin{p});
end
vec=cat(2,r{:});
if any(qnum) && qchar && ~qcell
% last step
vec=[vec{:}];
end
|