/usr/share/psychtoolbox-3/PsychOneliners/Struct2Vect.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 | function vec = Struct2Vect(struc,fieldnm)
% vec = Struct2Vect(struc,fieldnm)
% Traverses array of structs STRUC and returns data from all fields FIELDNM
% in vector VEC.
% Returns array vector if field contains numeric scalars or scalar structs,
% cell vector otherwise. If concatenating struct arrays, each struct must
% contain the same fields
%
% Example: for field data.field:
% data(1).field = 23;
% data(2).field = 56;
% vec = Struct2Vect(data,'field')
% vec = [23 56];
%
% Example: for field data2.test:
% data2(1).test = 23;
% data2(2).test = 'd';
% vec = Struct2Vect(data2,'test')
% vec = {23 'd};
%
% Example: for field data3.cells:
% data3(1).cells = 23;
% data3(2).cells = [42 45];
% vec = Struct2Vect(data3,'cells')
% vec = {23, [42 45]};
%
% Example: for field data4.struc:
% data4(1).struc.a = 24;
% data4(2).struc.a = [42 45];
% vec = Struct2Vect(data4,'struc')
% vec(1).a = 24;
% vec(2).a = [42 45];
% DN 2007
% DN 2008-07-30 Fixed handling of numeric vectors
% DN 2012-06-12 Better tests for numeric scalar, now tests all elements in
% array. Can now handle struct arrays
isnumer = arrayfun(@(x) isnumeric(x.(fieldnm)),struc); isnumer = all(isnumer(:));
isstruc = arrayfun(@(x) isstruct(x.(fieldnm)),struc); isstruc = all(isstruc(:));
isscala = arrayfun(@(x) isscalar(x.(fieldnm)),struc); isscala = all(isscala(:));
if (isnumer || isstruc) && isscala
vec = [struc.(fieldnm)];
else % not numeric scalar, make cellarray
vec = {struc.(fieldnm)};
end
|