octave-patch-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-patch-tracker] [patch #7632] sub2ind and ind2sub for tringular m


From: Juan Pablo Carbajal
Subject: [Octave-patch-tracker] [patch #7632] sub2ind and ind2sub for tringular matrices
Date: Wed, 12 Oct 2011 16:22:34 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Ubuntu/10.10 (maverick) Firefox/3.6.23

URL:
  <http://savannah.gnu.org/patch/?7632>

                 Summary: sub2ind and ind2sub for tringular matrices
                 Project: GNU Octave
            Submitted by: juanpi
            Submitted on: Wed 12 Oct 2011 04:22:34 PM GMT
                Category: None
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:


This is related to 
http://octave.1599824.n4.nabble.com/Re-OctDev-sub2ind-for-Upper-triangular-matrices-td3845392.html

Attached find two functions that do what is required. They are vectorized.
sub2ind_tril is using sub2ind, maybe there is a more efficient way of doing
this.

To merge ind2sub_tril with current ind2sub one needs to add a check for string
arguments and modify the docstring. Also, ind2sub_tril returns a row matrix.

## @deftypefnx {Function File} { @var{ind} = } sub2ind (@dots{}, @var{type}) 

## where @var{type} can be 'triu' or 'tril'

The body reads

type_str = varargin{ cellfun (@ischar, varargin) }
if !isempty (type_str)

 ind = sub2ind_tril (N, row, col)
 return
end 

To merge sub2ind_tril with current sub2ind. change the docstring similarly as
before, and the body of the function reads

type_str = varargin{ cellfun (@ischar, varargin) }
if !isempty (type_str)

 [r c] = ind2sub_tril (N, ind)

 if strcmp (type_str, 'triu')
    [r c] = deal (c,r);
 end

 return
end 




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Wed 12 Oct 2011 04:22:34 PM GMT  Name: ind2sub_tril.m  Size: 1kB   By:
juanpi
Octave functions
<http://savannah.gnu.org/patch/download.php?file_id=24135>
-------------------------------------------------------
Date: Wed 12 Oct 2011 04:22:34 PM GMT  Name: sub2ind_tril.m  Size: 1kB   By:
juanpi
Octave functions
<http://savannah.gnu.org/patch/download.php?file_id=24136>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/patch/?7632>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]