Merge pull request #41 from blackducksw/ubuntu_14
[ohcount] / test / expected_dir / scilab.sci
1 scilab  comment // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 scilab  comment // Copyright (C) INRIA - Serge STEER
3 scilab  comment // 
4 scilab  comment // This file must be used under the terms of the CeCILL.
5 scilab  comment // This source file is licensed as described in the file COPYING, which
6 scilab  comment // you should have received as part of this distribution.  The terms
7 scilab  comment // are also available at
8 scilab  comment // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9 scilab  blank   
10 scilab  code    function I=sub2ind(dims,varargin)
11 scilab  comment //sub2ind is used to determine the equivalent single index
12 scilab  comment //corresponding to a given set of subscript values.
13 scilab  blank   
14 scilab  comment //I = sub2ind(dims,i1,i2,..) returns the linear index equivalent to the
15 scilab  comment //row,  column, ... subscripts in the arrays i1,i2,..  for an matrix of
16 scilab  comment //size dims.
17 scilab  blank   
18 scilab  comment //I = sub2ind(dims,Mi) returns the linear index
19 scilab  comment //equivalent to the n subscripts in the columns of the matrix Mi for a matrix
20 scilab  comment //of size dims.
21 scilab  blank   
22 scilab  code      d=[1;cumprod(matrix(dims(1:$-1),-1,1))]
23 scilab  code      for i=1:size(varargin)
24 scilab  code        if varargin(i)==[] then I=[],return,end
25 scilab  code      end
26 scilab  blank   
27 scilab  code      if size(varargin)==1 then //subindices are the columns of the argument
28 scilab  code        I=(varargin(1)-1)*d+1
29 scilab  code      else //subindices are given as separated arguments
30 scilab  code        I=1
31 scilab  code        for i=1:size(varargin)
32 scilab  code          I=I+(varargin(i)-1)*d(i)
33 scilab  code        end
34 scilab  code      end
35 scilab  code    endfunction