File: scilab.sci

package info (click to toggle)
ruby-pygments.rb 0.6.3-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,628 kB
  • sloc: python: 46,993; ansic: 8,115; lisp: 3,703; cobol: 2,961; pascal: 2,750; ruby: 2,700; sh: 2,362; java: 1,755; cpp: 1,549; haskell: 926; ml: 831; csh: 681; f90: 459; php: 260; cs: 258; perl: 177; makefile: 174; ada: 161; objc: 145; erlang: 104; awk: 94; asm: 68; jsp: 21
file content (30 lines) | stat: -rw-r--r-- 891 bytes parent folder | download
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
// Scilab ( http://www.scilab.org/ )
// Copyright (C) INRIA - Serge STEER
// 

function I=sub2ind(dims,varargin)
//sub2ind is used to determine the equivalent single index
//corresponding to a given set of subscript values.
 
//I = sub2ind(dims,i1,i2,..) returns the linear index equivalent to the
//row,  column, ... subscripts in the arrays i1,i2,..  for an matrix of
//size dims.
 
//I = sub2ind(dims,Mi) returns the linear index
//equivalent to the n subscripts in the columns of the matrix Mi for a matrix
//of size dims.
 
  d=[1;cumprod(matrix(dims(1:$-1),-1,1))]
  for i=1:size(varargin)
    if varargin(i)==[] then I=[],return,end
  end

  if size(varargin)==1 then //subindices are the columns of the argument
    I=(varargin(1)-1)*d+1
  else //subindices are given as separated arguments
    I=1
    for i=1:size(varargin)
      I=I+(varargin(i)-1)*d(i)
    end
  end
endfunction