Home > tt2 > core > tt_ind2sub.m

tt_ind2sub

PURPOSE ^

Correct conversion of an index to a multiindex

SYNOPSIS ^

function [ind] = tt_ind2sub(siz,ndx)

DESCRIPTION ^

Correct conversion of an index to a multiindex
   [IND]=TT_IND2SUB(SIZ,NDX) 


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------
ind=tt_ind2sub(size,ndx)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ind] = tt_ind2sub(siz,ndx)
0002 %Correct conversion of an index to a multiindex
0003 %   [IND]=TT_IND2SUB(SIZ,NDX)
0004 %
0005 %
0006 % TT-Toolbox 2.2, 2009-2012
0007 %
0008 %This is TT Toolbox, written by Ivan Oseledets et al.
0009 %Institute of Numerical Mathematics, Moscow, Russia
0010 %webpage: http://spring.inm.ras.ru/osel
0011 %
0012 %For all questions, bugs and suggestions please mail
0013 %ivan.oseledets@gmail.com
0014 %---------------------------
0015 %ind=tt_ind2sub(size,ndx)
0016 
0017 %nout = max(nargout,1);
0018 nout = size(siz,2);
0019 
0020 siz = double(siz);
0021 ind=zeros(1,nout);
0022 if length(siz)<=nout,
0023   siz = [siz ones(1,nout-length(siz))];
0024 else
0025   siz = [siz(1:nout-1) prod(siz(nout:end))];
0026 end
0027 n = length(siz);
0028 k = [1 cumprod(siz(1:end-1))];
0029 for i = n:-1:1,
0030   vi = rem(ndx-1, k(i)) + 1;         
0031   vj = (ndx - vi)/k(i) + 1; 
0032   ind(i) = vj; 
0033   ndx = vi;     
0034 end

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005