Boost logo

Ublas :

Subject: [ublas] Sub-matrix Question
From: Bin Dai (daibin84_at_[hidden])
Date: 2010-10-29 01:21:29


Hi,

I am working a a project that I need to use a sub-matrix of a given
matrix, the MATLAB code is as follows:

>> M = reshape(1:18, 3, 6)

M =

     1 4 7 10 13 16
     2 5 8 11 14 17
     3 6 9 12 15 18

>> subM = M(2:3, [1, 4, 6])

subM =

     2 11 17
     3 12 18

the subM is the one I want. I understand there are very convenient
tools 'range' and 'slice' but I am trying to get a general one such as
[1, 4, 6] in the previous example.
In addition, I read the thread on
http://archives.free.net.ph/message/20100723.123350.753d32ba.en.html
using indirect_array but I want a better one such as indexing the rows
with range by the columns with indirect_array.

I know I can do it by constructing a new matrix with elements from the
original matrix but I want a more efficient one so I can save a little
memory when dealing with large=scale matrix.

Thanks

Bin