File: IsACell.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (43 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (6)
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
function bool = IsACell(input,fhndl)
% bool = IsACell(input,fhndl)
% 
% checks if there is any element in the cell INPUT that satisfies the
% logical condition in function FHNDL
% works recursively: cells in cells (etc) also checked
% the function FHNDL must return a scalar
%
% examples:
% checks if there is any struct in the cell:
% fhndl = @isstruct
% check if there is any element in the cell extending
% over more than 2 dimensions:
% fhndl = @(x)ndims(x)>2
%
% DN    2008-05-28

psychassert(iscell(input),'IsACell: Input must be cell, not %s',class(input));

if fhndl(input)
    bool = true;
    return;
else
    bool = false;
end

qtest   = cellfun(fhndl,input);
qcell   = cellfun(@iscell,input);

if AnyAll(qtest)
    % cell found with data in it that satisfies the logical condition in
    % FHNDL
    bool    = true;
elseif AnyAll(qcell)
    % cells found in the cell, process also
    [lind]       = find(qcell);
    for p=1:length(lind)
        bool    = IsACell(input{lind(p)},fhndl);
        if bool
            return;
        end
    end
end