bugGNU Octave - Bugs: bug #54436, get (gca, 'yticklabel') returns...

 
 

bug #54436: get (gca, 'yticklabel') returns cellstr row vector versus cellstr column vector in Matlab

Submitter:  Arnaud Delorme <arnodelorme>
Submitted:  Thu 02 Aug 2018 05:15:34 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 4.4.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 03 Aug 2018 06:20:04 PM UTC, comment #6: 

So, it would seem that the general rule is that numeric vectors are always row vectors, while cell array of strings are always column vectors.  Octave is consistent in producing row vectors for both data types.  Changing this doesn't look straightforward, so it is probably easier to change code to make it independent of the particular orientation.  An easy workaround is to use '(:)' to force a column vector orientation.  In other words,


labels = get (gca, 'yticklabel');
->
labels = get (gca, 'yticklabel')(:);
OR
labels = get (gca, 'yticklabel');
labels = labels(:);



Rik <rik5>
Group administrator
Thu 02 Aug 2018 09:17:49 PM UTC, comment #5: 

diary on
h = plot (1:10);
get (gca, 'xtick')
get (gca, 'xticklabel')
set (gca, 'xtick', [0, 5, 10])
get (gca, 'xtick')
get (gca, 'xticklabel')
set (gca, 'xtick', [1, 4, 9]')
get (gca, 'xtick')
get (gca, 'xticklabel')
set (gca, 'xticklabel', {'A', 'B', 'C'})
get (gca, 'xticklabel')
set (gca, 'xticklabel', {'D'; 'E'; 'F'})
get (gca, 'xticklabel')
diary off

ans =

     0     5    10


ans =

  3×1 cell array

    {'0' }
    {'5' }
    {'10'}


ans =

     0     5    10


ans =

  3×1 cell array

    {'0' }
    {'5' }
    {'10'}


ans =

     1     4     9


ans =

  3×1 cell array

    {'1'}
    {'4'}
    {'9'}


ans =

  3×1 cell array

    {'A'}
    {'B'}
    {'C'}


ans =

  3×1 cell array

    {'D'}
    {'E'}
    {'F'}

(file #44692)

Arnaud Delorme <arnodelorme>
Thu 02 Aug 2018 09:00:18 PM UTC, comment #4: 

Can you run some code to determine how Matlab behaves under various circumstances?


diary on
h = plot (1:10);
get (gca, 'xtick')
get (gca, 'xticklabel')
set (gca, 'xtick', [0, 5, 10])
get (gca, 'xtick')
get (gca, 'xticklabel')
set (gca, 'xtick', [1, 4, 9]')
get (gca, 'xtick')
get (gca, 'xticklabel')
set (gca, 'xticklabel', {'A', 'B', 'C'})
get (gca, 'xticklabel')
set (gca, 'xticklabel', {'D'; 'E'; 'F'})
get (gca, 'xticklabel')
diary off


This will create a diary file that you can then just upload.

Rik <rik5>
Group administrator
Thu 02 Aug 2018 06:12:08 PM UTC, comment #3: 

Actually Octave and Matlab are inverted in my example

Octave 4.4.0
[1,1] = 1.09861
[1,2] = 1.17017
[1,3] = 1.24174
[1,4] = 1.3133
[1,5] = 1.38486
[1,6] = 1.45642


Matlab 2018a
{'1.0986'}
{'1.1702'}
{'1.2417'}
{'1.3133'}
{'1.3849'}
{'1.4564'}

Arnaud Delorme <arnodelorme>
Thu 02 Aug 2018 05:24:14 PM UTC, comment #2: 

Another difference is that Matlab forces the string to be of the same length for each tick label while Octave does not. This is not reflected in this example.But see below

  [1,1] = 1.09861
  [1,2] = 1.17017
  [1,3] = 1.24174
  [1,4] = 1.3133
  [1,5] = 1.38486
  [1,6] = 1.45642
 
And Octave 4.4.0

    {'1.0986'}
    {'1.1702'}
    {'1.2417'}
    {'1.3133'}
    {'1.3849'}
    {'1.4564'}

Arnaud Delorme <arnodelorme>
Thu 02 Aug 2018 05:21:17 PM UTC, comment #1: 

Actually the issue is not with the type of data (they are both strings), but with the dimension.

Matlab returns the labels in the first dimension and Octave in the second dimension. This messes up my script.

Arnaud Delorme <arnodelorme>
Thu 02 Aug 2018 05:15:34 PM UTC, original submission:  

Matlab returns string values and Octave numerical ones. Not that critical although it does break my unit tests (and the complex figure I am trying to plot). I have implemented a workaround but thought it would be important to report it.

figure; imagesc(rand(10,10));

>> tmpval = get(gca,'yticklabel')


tmpval =

  10×1 cell array
{
    {'1' }
    {'2' }
    {'3' }
    {'4' }
    {'5' }
    {'6' }
    {'7' }
    {'8' }
    {'9' }
    {'10'}
}

Under Octave 4.4

figure; imagesc(rand(10,10));

>>  tmpval = get(gca,'yticklabel')

tmpval =
{
  [1,1] = 2
  [1,2] = 4
  [1,3] = 6
  [1,4] = 8
  [1,5] = 10
}


Arnaud Delorme <arnodelorme>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #44692:  diary added by arnodelorme (1KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by arnodelorme (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-08-03 rik5 StatusNeed Info Confirmed
        Operating SystemMac OS Any
        Summaryyticklabel difference with Matlab get (gca, 'yticklabel') returns cellstr row vector versus cellstr column vector in Matlab
    2018-08-02 arnodelorme Attached File- Added diary, #44692
    2018-08-02 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code