bugGNU Octave - Bugs: bug #43017, "text" command does not...

 
 

bug #43017: "text" command does not work with empty matrix to indicate empty line

Submitter:  Hartmut <hardy>
Submitted:  Mon 18 Aug 2014 07:47:58 PM UTC
   
 
Category:  Plotting with OpenGL Severity:  3 - Normal
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.8.2 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 29 Sep 2015 07:50:39 PM UTC, comment #9: 

@Harmut: Thanks for the extensive testing.  Octave generally likes to think of itself as a superset of Matlab, rather than bug-for-bug compatible.  Therefore, it doesn't bother me at all that Octave offers more functionality when it comes to multiple objects and multi-line strings.  I changed the FIXME comment to just a NOTE to explain the differnce.  Thanks to your testing, which shows Octave is compatible, I deleted the other two FIXME comments.  See this cset (http://hg.savannah.gnu.org/hgweb/octave/rev/50bf240978e6).

Rik <rik5>
Group administrator
Tue 29 Sep 2015 06:54:51 PM UTC, comment #8: 

Thanks for the elegant patch, Rik!

Seems that I was a couple of hours too late with my testing, this time. But I HAVE tested your patch, and observed that it fully fixes the topic of this bug. And I couldn't find any harmful sideeffects of this patch either. Now it's pushed to the repository, anyways. So far so good.

But I also stumbled across the three "Fixme, is it Matlab compatible?" comments in the test section of text.m . And I did run those three tests on Matlab, to check for Matlab compatibility. Doing this, I observed several incompatiblities which I will list in the remainder of this post. Maybe you, Rik, could give me some feedback if it's worth posting a seperate bug report about any of those.

But first the details. I run the following script both in Matlab 2013b and in 2014b:

clear, close all;
clc
format compact

%% Multiple objects with single line
h = text ([0.1, 0.1], [0.5, 0.6], {'two objects with same cellstr'});
class (get (h(1), 'string'))
class (get (h(2), 'string'))
get (h(1), 'string')
get (h(2), 'string')

%% Multiple objects with same multi-line string which has empty cell
h = text ([0.7, 0.7, 0.7], [0.3, 0.5, 0.7], {'Line1'; []; 'Line3'});
class (get (h(1), 'string'))
class (get (h(2), 'string'))
get (h(1), 'string')
get (h(2), 'string')

%% Multiple objects with multiple lines
h = text ([0.1, 0.1], [0.7, 0.8], {'cellstr1', 'cellstr2'});
class (get (h(1), 'string'))
class (get (h(2), 'string'))
get (h(1), 'string')
get (h(2), 'string')


The result in Matlab 2013b was:

ans =
char
ans =
char
ans =
two objects with same cellstr
ans =
two objects with same cellstr

ans =
char
ans =
char
ans =
Line1
ans =
   Empty string: 1-by-0

ans =
char
ans =
char
ans =
cellstr1
ans =
cellstr2


The result in Matlab 2014b was:

ans =
cell
ans =
cell
ans =
    'two objects with same cellstr'
ans =
    'two objects with same cellstr'

ans =
char
ans =
char
ans =
Line1
ans =
     ''

ans =
char
ans =
char
ans =
cellstr1
ans =
cellstr2


The result with Octave 4.0.0 with your latest patch (of this bug report) applied is:

ans = cell
ans = cell
ans =
{
  [1,1] = two objects with same cellstr
}
ans =
{
  [1,1] = two objects with same cellstr
}

ans = cell
ans = cell
ans =
{
  [1,1] = Line1
  [2,1] =
  [3,1] = Line3
}
ans =
{
  [1,1] = Line1
  [2,1] =
  [3,1] = Line3
}

ans = char
ans = char
ans = cellstr1
ans = cellstr2


From this I have drawn the following conclusions:

  • The second "fixme test" ("Multiple objects with same multi-line string which has empty cell") isn't Matlab compatible at all. I needed to add two numbers to the code, in order to make it work: h = text ([0.7, 0.7, 0.7], [0.3, 0.5, 0.7], {'Line1'; []; 'Line3'}); This means: If you give Matlab a cell array with three entries and only two x-y-coordinates  (as does the original test), it will throw an error ("Each string specified must have a corresponding set of coordinates"). Octave currently does NOT throw this error. Instead Octave will plot each text line twice! So Octave is more tolerant, but produces unexpected results. Shall I open a seperate bug report for this?  (A)


  • The first "fixme test" produces cell results with Octave. This is the same result as Matlab 2014b. In Matlab 2013b the result was still a char. So I would consider this (currently) Matlab compatible -> OK.


  • The second "fixme test" (corrected, as discussed above) produces cell results with Octave. But both in Matlab 2013b and 2014b it produces character arrays as results. So this is NOT Matlab compatible right now. Shall I open a seperate bug report for this? (B)


  • The third "fixme test" produces character array as result, in Octave as well as in Matlab 2013b and 2014b. So this test is fully Matlab compatible right now. This means you could remove the comment "## FIXME: is return value really char in Matlab?" in the current source code of this Octave test.  (C)


Let me know if you think it's useful to open a new bug report for any of the two real incompatiblities (A or B) listed above. If you like to, go ahead and just remove the fixme comment in the third test (C).

Hartmut <hardy>
Tue 29 Sep 2015 01:30:41 PM UTC, comment #7: 

I pushed the changeset to the development branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/ecca28364445).  Closing report.

Rik <rik5>
Group administrator
Sun 27 Sep 2015 05:16:16 AM UTC, comment #6: 

Attached is a different way of tackling the problem that is faster because it does not use for loops.  It seems to work for me, but please apply it and check for yourself.  If good, I will add a ChangeLog message and commit it.

(file #34994)

Rik <rik5>
Group administrator
Sat 26 Sep 2015 07:14:49 PM UTC, comment #5: 

Ooops, yes. Very simple "text" commands like this don't work any more with this first patch:

close all, text(0.5, 0.5, 'Hello')

It seemFs to me that you try to index a cell array (with curly brackets) in your patch. This one works fine with your patch for example:

close all, text(0.5, 0.5, {'Hello'})

But single line texts aren't necessarily a cell array :( Plus: Even multi-line texts can still be a character array. This one should also be preserved to work (and doesn't with this first patch):

close all, text(0.5, 0.5, ['Hello'; '12345'])

Suggestion: Could you maybe change this patch, such that it  starts to look for emtpy strings (using the cell array indexing, that currently throws an error) ONLY IF the whole text object is surely a cell array? In all other cases (i.e. having character arrays) there cannot be an empty line in there anyways, because array cannot have missing elements! So there is nothing to fix for those other cases with character arrays.


Hartmut <hardy>
Sat 26 Sep 2015 06:50:38 PM UTC, comment #4: 

Well, there is a problem, with this patch.
Use for example, the code from bug #46037


close all
graphics_toolkit gnuplot
ht = text (0.5, 0.5, '\bf Hello')


I get a lot of errors. Back to square 1.

Avinoam Kalma <avinoam>
Group Member
Thu 24 Sep 2015 07:29:27 PM UTC, comment #3: 

Thank you for this patch, Avinoam.

I have tested the behavior of this patch. And yes, it seems to properly fix the described behavior in this bug report :)

I cannot judge if this patch would have any side effects. To judge this, I do not understand enough of the code in text.m.

I would be happy to see this patch included into the next release of Octave (unless someone has a good reason why it shouldn't).

Hartmut <hardy>
Fri 18 Sep 2015 10:11:29 PM UTC, comment #2: 


Here is a simple patch which searches for an empty string ([] or '')
and replace it with ''.

Please review.


(file #34924)

Avinoam Kalma <avinoam>
Group Member
Mon 18 Aug 2014 09:17:56 PM UTC, comment #1: 

Octave expects the inputs to text() to be strings.  For a workaround, use an empty string ('') rather than an empty matrix ([]).

I've marked this as a compatibility bug.

Rik <rik5>
Group administrator
Mon 18 Aug 2014 07:47:58 PM UTC, original submission:  

Here is an example to demonstrate the unwanted behavior:


close all;
figure(1);

Info1 = {'line 1', 'line 2', 'line 3' };
Info2 = {'line 1', [], 'line 3' };

text(0.5,0.7,Info1);
text(0.5,0.3,Info2);


The second text block is NOT properly displayed. This happens with gnuplot as well as with fltk. But in Matlab this works fine.

Hartmut <hardy>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #34994:  patch.text added by rik5 (4KiB - text/plain)
file #34924:  bug43017.cs added by avinoam (1KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by avinoam (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by hardy (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-09-29 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2015-09-27 rik5 Attached File- Added patch.text, #34994
        StatusConfirmed Patch Submitted
    2015-09-18 avinoam Attached File- Added bug43017.cs, #34924
    2014-09-26 rik5 StatusNone Confirmed
    2014-09-26 rik5 Priority5 - Normal 3 - Low
    2014-08-18 rik5 Summary&quot;text&quot; command does not work with empty lines "text" command does not work with empty matrix to indicate empty line
    2014-08-18 rik5 Item GroupIncorrect Result Matlab Compatibility

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code