]> Creatis software - CreaPhase.git/blob - octave_packages/dataframe-0.9.1/@dataframe/find.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / dataframe-0.9.1 / @dataframe / find.m
1 function varargout = find(df, varargin) 
2
3   %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
4   %%
5   %% This file is part of Octave.
6   %%
7   %% Octave is free software; you can redistribute it and/or
8   %% modify it under the terms of the GNU General Public
9   %% License as published by the Free Software Foundation;
10   %% either version 2, or (at your option) any later version.
11   %%
12   %% Octave is distributed in the hope that it will be useful,
13   %% but WITHOUT ANY WARRANTY; without even the implied
14   %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15   %% PURPOSE.  See the GNU General Public License for more
16   %% details.
17   %%
18   %% You should have received a copy of the GNU General Public
19   %% License along with Octave; see the file COPYING.  If not,
20   %% write to the Free Software Foundation, 51 Franklin Street -
21   %% Fifth Floor, Boston, MA 02110-1301, USA.
22
23   %#
24   %# $Id: find.m 9585 2012-02-05 15:32:46Z cdemills $
25   %#
26
27   switch nargout
28     case {0, 1}
29       resu = []; mz = max(cellfun(@length, df._rep));
30       for indc = 1:df._cnt(2),
31         [indr, inds] = feval(@find, df._data{indc}(:, df._rep{indc}));
32         %# create a vector the same size as indr
33         dummy = indr; dummy(:) = indc;
34         resu = [resu; sub2ind([df._cnt(1:2) mz], indr, dummy, inds)];
35       endfor
36       varargout{1} = sort(resu);
37     case 2
38       nz = 0; idx_i = []; idx_j = [];
39       for indc = 1:df._cnt(2),
40         [dum1, dum2] = feval(@find, df._data{indc}(:, df._rep{indc}));
41         idx_i = [idx_i; dum1];
42         idx_j = [idx_j; nz + dum2];
43         nz = nz + df._cnt(1)*length(df._rep{indc});
44       endfor
45       varargout{1} = idx_i; varargout{2} = idx_j;
46     case 3
47       nz = 0; idx_i = []; idx_j = []; val = [];
48       for indc = 1:df._cnt(2),
49         [dum1, dum2, dum3] = feval(@find, df._data{indc}(:, df._rep{indc}));
50         idx_i = [idx_i; dum1];
51         idx_j = [idx_j; nz + dum2];
52         val = [val; dum3];
53         nz = nz + df._cnt(1)*length(df._rep{indc});
54       endfor
55       varargout{1} = idx_i; varargout{2} = idx_j; varargout{3} = val;
56     otherwise
57       print_usage('find');
58   endswitch
59
60 endfunction