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

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

[Octave-bug-tracker] [bug #63833] Matrix indexing is inconsistent


From: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #63833] Matrix indexing is inconsistent
Date: Fri, 24 Feb 2023 11:39:53 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?63833>

                 Summary: Matrix indexing is inconsistent
                   Group: GNU Octave
               Submitter: arungiridhar
               Submitted: Fri 24 Feb 2023 11:39:51 AM EST
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Inaccurate Result
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: dev
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Fri 24 Feb 2023 11:39:51 AM EST By: Arun Giridhar <arungiridhar>
A 2x3 index matrix gives a 2x3 result and a 3x2 index matrix gives a 3x2
result, as expected:

>> x = (1:3);

>> x([2 3 1; 3 1 2])
ans =

   2   3   1
   3   1   2

>> x([2 3 1; 3 1 2]')
ans =

   2   3
   3   1
   1   2


But if the index matrix is a vector, then the result is always a row vector,
never a column vector.

>> x([2 3 1])
ans =

   2   3   1

>> x([2 3 1]')
ans =

   2   3   1


Transposing the original matrix (not the index matrix) causes the result to
also always be transposed:

>> y = x';

>> y([2 3 1])
ans =

   2
   3
   1

>> y([2 3 1]')
ans =

   2
   3
   1


But if the original matrix is bigger than just a single row or column, then
the indexing does behave as expected.

octave:7> A = [1 2; 3 4]
A =

   1   2
   3   4

octave:8> A([1 2])
ans =

   1   3

octave:9> A([1 2]')
ans =

   1
   3


Unless this inconsistent behavior is done to satisfy some weird Matlab quirk,
it feels like a bug. What is the context for this?

Documentation page doesn't mention this behavior:
https://docs.octave.org/latest/Index-Expressions.html







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63833>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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