bugGNU Octave - Bugs: bug #56395, text objects should auto-convert...

 
 

bug #56395: text objects should auto-convert numeric entries to text using sprintf ("%g")

Submitter:  None
Submitted:  Sun 26 May 2019 05:52:02 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  G Aliev Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 29 Jul 2019 04:20:50 PM UTC, comment #6: 

I changed this for Matlab compatibility in this cset (https://hg.savannah.gnu.org/hgweb/octave/rev/6ec7b2e73b5b) and added the code in comment #4 as a BIST test.  This will be released in the 6.1 version of Octave, or you can simply download the text.m m-file from Mercurial to get the change in your current distribution.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Tue 28 May 2019 04:44:11 AM UTC, comment #5: 

Re-titling to reflect the root incompatibility.

In the meantime, there are easy workarounds.  Use "" to indicate an empty value rather than [].  And use num2str or sprintf to convert numeric values to text before inclusion in a text object.

Rik <rik5>
Group administrator
Mon 27 May 2019 09:09:59 PM UTC, comment #4: 

@Rik: In addition to char arrays, and strings Matlab also allows numeric values (and others) to be passed. It also allows cell arrays of all those types mixed, e.g.


text (.3, .8, {"Hello", 'world', [], 123})


produces a 4 lines text object that looks like


Hello
world

123


Precisely they say:

>> Text that contains only a numeric value is converted using sprintf('%g',value)


And indeed, "sprintf ("%g", [])" does produce an empty string in Octave as well.

Pantxo Diribarne <pantxo>
Group Member
Mon 27 May 2019 07:52:51 PM UTC, comment #3: 

I was wrong about no error during execution in Octave's command line in 3d case - my no-error result was from mistakenly used Matlab's workspace.

Gazi Aliev <gazi>
Mon 27 May 2019 03:36:55 PM UTC, comment #2: 

The title() function expects a character array or a cell array of strings.  A construct like


C = {'line1', [], 'line3'};


is a true cell array with mixed data types.  You can convert to a true cell array of strings with the cellstr() function.


Cs = cellstr (C);
title (Cs);



Rik <rik5>
Group administrator
Sun 26 May 2019 07:36:23 PM UTC, comment #1: 

Use 'warning ("off", "Octave:num-to-str")' if you want to avoid the implicit conversion warning, trivially solved as a user preference.

The remaining error in the title function I can confirm, but I confirm that the same error happens at the command line and in a script, that strange difference is not real.

The error in a clean workspace is


>> title ({'Figure'; []})
error: invalid conversion from real matrix to real scalar
error: called from
    __axis_label__ at line 31 column 3
    title at line 51 column 8


And this error is directly attributable to the following example


>> h = text (1, 1, ''); axis ([0 2 0 2])
>> set (h, "string", {"some text"; []})
error: invalid conversion from real matrix to real scalar


I can confirm using Matlab's online script tool that both of these do work in Matlab without error or warning.

Mike Miller <mtmiller>
Group Member
Sun 26 May 2019 05:52:02 PM UTC, original submission:  


>> a=['text',[]]

a = text
no warning

>> a='text'; b=[a,[]]

warning: implicit conversion from numeric to char

title({'text';[]}) or title({a;[]}) - is OK if it is executed in command line, however, if it is executed within a function, then the both versions give no title and the error:
error: invalid conversion from real matrix to real scalar execution
error in graphics callback function  

title({'text';''}) or title({a;''}) - works OK in the same function


Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by gazi (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (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 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-08 None Carbon-CopyRemoved -
    2019-07-29 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
        Release5.1.0 dev
    2019-05-28 rik5 Priority5 - Normal 3 - Low
        Summarytext object error: invalid conversion from real matrix to real scalar text objects should auto-convert numeric entries to text using sprintf ("%g")
    2019-05-27 mtmiller Carbon-CopyRemoved mtmiller -
    2019-05-27 gazi Carbon-Copy- Added mtmiller
        Carbon-Copy- Added
    2019-05-26 mtmiller Severity3 - Normal 2 - Minor
        StatusNone Confirmed
        Operating SystemMicrosoft Windows Any
        Summaryimplicit conversion from numeric to char text object error: invalid conversion from real matrix to real scalar

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code