bugGNU Octave - Bugs: bug #49143, inputdlg processes 2 element row...

 
 

bug #49143: inputdlg processes 2 element row vector rowscols input as heights instead of height and width

Submitter:  Avinoam Kalma <avinoam>
Submitted:  Tue 20 Sep 2016 05:33:54 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Postponed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 18 Oct 2023 09:04:22 PM UTC, comment #19: 

i take it back.  their documentaion when from ambiguous, to just conflicting with matlab behavior.  for dims = [1 10], if there are 2 inputs, and 2 elements to dim, it should follow option 2, as octave does.  currently matlab 2023b follows option 3 even though there is only 1 row to dim but 2 inputs.

i'll follow up on their bug report.  but at least it seems their help text matches what octave has been doing. we'll see if that changes.

Nicholas Jankowski <nrjank>
Group Member
Wed 18 Oct 2023 08:57:01 PM UTC, comment #18: 

update to the bug report indicated that this issue had been fixed in R3032b.  looking at the online documentation, the variable 'dims' is now called 'fieldsize', and the comment #13 text now states:


Text edit field height and width, specified as a scalar, vector, or matrix.

* If fieldsize is a scalar, then it specifies the height for all edit fields in lines of text. The width for all edit fields is the maximum that the dialog box allows.

* If fieldsize is a column or row vector with number of elements equal to the number of prompts, then each element specifies the height of each corresponding edit field from the top to the bottom of the dialog box. The width for all edit fields is the maximum that the dialog box allows.

* If fieldsize is an m-by-2 matrix with m equal to the number of prompts, then each row refers to the size of the edit field for the corresponding prompt. The first column specifies the height of the edit field in lines of text. The second column specifies the width of that edit field in character units. The width of a character unit equals the width of the letter x when using the system font.


the colormap example has been changed to have a 2 row input:


prompt = {'Enter matrix size:','Enter colormap name:'};
dlgtitle = 'Input';
fieldsize = [1 45; 1 45];
definput = {'20','hsv'};
answer = inputdlg(prompt,dlgtitle,fieldsize,definput)


that produces the same output as octave.

however all of the comment #13 examples produce the same output in matlab 2023b. the ambiguous 1x2 dim input is still ambiguous between the two input formats, and arbitrarily follows option 3 while octave follows option 2. (one would think the options would match the precedence order, but apparently it doesn't.)

so they haven't changed behavior, just changed the example highlighting the ambiguity, but the ambiguity still exists.

Nicholas Jankowski <nrjank>
Group Member
Tue 11 Oct 2022 09:23:20 PM UTC, comment #17: 

(noting that current behavior is unchanged in matlab 2022b)

Nicholas Jankowski <nrjank>
Group Member
Tue 11 Oct 2022 09:17:55 PM UTC, comment #16: 

just adding a note that mathworks support indicated that the current conflicting behavior is considered a bug, not just a documentation error. So, will keep this as Postponed for the time being and keep an eye on the matlab release notes.

Nicholas Jankowski <nrjank>
Group Member
Thu 15 Sep 2022 03:04:07 PM UTC, comment #15: 

glad to hear it, Faith.

Looking at it a bit more, this situation sits at the intersection of two different handling methods. A 1xm row vector is clearly handled for any m all the way down to 1, except for m=2 , where it collides with the different behavior for the nx2 array method, which very clearly handles all values of n down to 1.  At that point they look identical, one should error if a count mismatch occurs, the other doesn't.  My guess is Matlab's decision to default to array behavior is an accidental artifact of their decision tree ordering rather than a deliberate choice, somewhat supported by the conflicting documentation which probably appeared sometime after they grafted 'or row vector' onto the column vector method.

I was thinking of patching this for compatibility, but I did submit a mathworks bug and for now I think it's best just to let this sit and see if anything comes out on either side of that. better than implementing a fix only for them to decide to change the other way.

Nicholas Jankowski <nrjank>
Group Member
Thu 15 Sep 2022 06:37:20 AM UTC, comment #14: 

Thank you so much for your helpful investigation. I managed to fix the issue and understand the reason why it happened.

Faith <coleman>
Wed 14 Sep 2022 07:25:43 PM UTC, comment #13: 

yes, [1 60; 1 30; 1 30] is the 'array input' option that both accept and treat the same. one row per prompt element, col 1 is height, col 2 is width. the issue seems to just be with what Matlab does with a 2 element row vector.

I've read through the public facing help and the examples more closely, and I think matlab's behavior is 'correct' and documented, but they have conflicting documentation. I'll submit a doc correction bug report to mathworks. Octave followed that conflicting piece, hence the current bug. Full explanation below.

I'm going to reopen the bug report for now since it's close enough to the original problem.


Matlab doc text currently states: 

First:

answer = inputdlg(prompt,dlgtitle,dims) specifies the height of each edit field when dims is a scalar value. When dims is an array, the first value in each array element sets the edit field height. The second value in each array element sets the edit field width.


Then later, specifically defining 'dims':

Text edit field height and width (dimensions), specified as one of these values:

* If dims is a scalar, then it specifies the height for all edit fields. Height is the distance between the baselines of two lines of text. The width for all edit fields is the maximum that the dialog box allows.

* If dims is a column vector or row vector, then each element specifies the height of each corresponding edit field from the top to the bottom of the dialog box. The width for all edit fields is the maximum that the dialog box allows.

* If dims is an array, then it must be size m-by-2, where m is the number of prompts in the dialog box. Each row refers to the edit field for the corresponding prompt. The first column specifies the height of the edit field in lines of text. The second column specifies the width of that edit field in character units. The width of a character unit equals the width of the letter x when using the system font.


Octave's help indicates that it followed the second set of instructions in it's implementation. However, the very first example on that page matches the comment #8 input triggering an error in Octave:


prompt = {'Enter matrix size:','Enter colormap name:'};
dlgtitle = 'Input';
dims = [1 35];
definput = {'20','hsv'};
answer = inputdlg(prompt,dlgtitle,dims,definput)


note that it has two prompts, and a single dim array, a 2 element row vector. Octave interprets this as the height (number of rows) of each prompt field, with the first 1 high, the other 35 high.  Matlab displays two prompts both sized to 1 high, 35 wide. So it matches the first statement in their help, but not the second.

proposing that we adjust the behavior to match the documented example.  a 2 element row vector is treated with the 'array' rules, implicitly expanded to each input prompt.

other examples to verify:


answer = inputdlg({'first', 'second', 'third'},'sample',[1; 10; 4])
--> Matlab: 3 prompts, heights 1, 10, and 4.
--> Octave: same

answer = inputdlg({'first', 'second', 'third'},'sample',[1, 10, 4])
--> Matlab: 3 prompts, heights 1, 10, and 4
--> Octave: same

answer = inputdlg({'first', 'second', 'third'},'sample',[1; 10])
--> Matlab: error, 3 inputs but only 2 heights specified
--> Octave: same

answer = inputdlg({'first', 'second', 'third'},'sample',[1, 10])
--> Matlab: 3 prompts, size 1x10, 1x10, 1x10
--> Octave: error, 3 inputs but only 2 heights specified

answer = inputdlg({'first', 'second'},'sample',[1; 10])
--> Matlab: 2 prompts, heights 1, 10
--> Octave: same

answer = inputdlg({'first', 'second'},'sample',[1, 10])
--> Matlab: 2 prompts, size 1x10, 1x10
--> Octave: 2 prompts, heights 1, 10

answer = inputdlg({'first'},'sample',[1; 10])
--> Matlab: error, 1 input but  2 heights specified
--> Octave: error, 1 input but 2 heights specified

answer = inputdlg({'first'},'sample',[1, 10])
--> Matlab: 1 prompt, size 1x10
--> Octave: same


Nicholas Jankowski <nrjank>
Group Member
Wed 14 Sep 2022 04:47:50 PM UTC, comment #12: 

so this works in octave

orientation = inputdlg({'axis x' ,'axis y','axis z'},'cosine directors',[1 60; 1 30; 1 30],{'0','-sind(180)','cosd(180)'});

Doug Stewart <dastew>
Wed 14 Sep 2022 04:31:10 PM UTC, comment #11: 

examples:

Matlab 2022a:

2 element row vector, 3 prompts

orientation = inputdlg({'axis x' ,'axis y','axis z'},'cosine directors',[1 70],{'0','-sind(180)','cosd(180)'})

produces dialog with 3 inputs, each 1 row high and 70 chars wide
Octave throws an error because the vector is supposed to have the same number of elements, each defining a height.

2 element row vector, 2 prompts

orientation = inputdlg({'axis y','axis z'},'cosine directors',[1 70],{'-sind(180)','cosd(180)'})

produces dialog with 2 inputs, each 1 row high and 70 chars wide
Octave produces a dialog with 2 inputs, the first 1 row high the second 70 rows high, as per the documented behavior.

2 element row vector, 2 prompts

orientation = inputdlg({'axis y','axis z'},'cosine directors',[1;70],{'-sind(180)','cosd(180)'})

produces dialog with 2 inputs, 2 inputs, the first 1 row high the second 70 rows high, as per the documented behavior.
Octave produces a dialog with 2 inputs, the first 1 row high the second 70 rows high, as per the documented behavior.


Nicholas Jankowski <nrjank>
Group Member
Wed 14 Sep 2022 04:19:28 PM UTC, comment #10: 

I'm surprised (but i guess not overly surprised) that the matlab code worked.  the [1 70] size input should through an error if it strictly followed their published documentation at:
https://www.mathworks.com/help/matlab/ref/inputdlg.html#d123e751295

note that this has changed a bit over the years, an older version of the matlab function inputs described at:
http://www.ece.northwestern.edu/local-apps/matlabhelp/techdoc/ref/inputdlg.html

but matlab is known to have unexpected undocumented behavior, which I believe this is.  the [1 70] input doesn't match any of the documented forms for that input, which Octave enforces.

if that input is a scalar, it applies that as height of all input fields in prompt.  if it's a 2d array, it has to have the same number of rows as elements in prompt and two elements in width, one specifying the height and the other the width of the respective dialog.  if it's a vector, as yours is, the old version said it had to be a column vector (the new version allows a row vector) where each element is the height of the respective dialog. implied is that it has to have the same number of elements as prompt, otherwise there is no definition for expected behavior.

matlab apparently has decided to implicitly expand row vectors to be interpreted in the array case, with the same definition [rows cols] applied to all inputs. playing around with different combinations, it seems arbitrary, and I'm not certain it's all intentional.  if you only have two prompts, [1 70] and [1;70] give you very different results despite what the help text says.

Nicholas Jankowski <nrjank>
Group Member
Wed 14 Sep 2022 02:53:39 PM UTC, comment #9: 

I am not an expert in this area but I tried:

orientation = inputdlg({'axis x' ,'axis y','axis z'},'cosine directors',[ 1],{'0','-sind(180)','cosd(180)'});

and it worked, no errors.

Does this help you?

Doug Stewart <dastew>
Wed 14 Sep 2022 01:40:15 PM UTC, comment #8: 

I am trying to run Matlab files with Octave. The issue arise when the following line in one of the files is processed:

orientation = inputdlg({'axis x' ,'axis y','axis z'},'cosine directors',[1 70],{'0','-sind(180)','cosd(180)'});

Of course in Matlab it works, while in Octvave I get the following error message (where "dati_input" is the name of the file including the previous coded line (line 7); main at line 1 is where I call "dati_input"):

error: inputdlg: ROWSCOLS vector does not match size of PROMPT
error: called from
    inputdlg at line 152 column 9
    dati_input at line 7 column 20
    main at line 1 column 1

Faith <coleman>
Wed 14 Sep 2022 12:43:36 PM UTC, comment #7: 

Then the  patch has already been applied to your version.
Please describe what your real problem is.

Doug Stewart <dastew>
Wed 14 Sep 2022 12:20:17 PM UTC, comment #6: 

I am using version 7.2.0. I recently downloaded it, it is supposed to be the newest one...

Faith <coleman>
Wed 14 Sep 2022 10:49:39 AM UTC, comment #5: 

You must be running an old version of octave!
What version do you have?
Try the newest version -- it is free.

Doug Stewart <dastew>
Wed 14 Sep 2022 09:11:26 AM UTC, comment #4: 

I need to fix the issue relevant to patch of comment #1. I'm just a beginner and I need to be guided step by step in what I have to do with the .cs patch downloaded. Namely, where to put it, how to run it, etc.
Is there anyone who can help me please?

Faith <coleman>
Fri 23 Sep 2016 01:07:36 PM UTC, comment #3: 

The patch of comment #1 works for me, too. All Matlab examples and the demos of inputdlg are running properly. Thanks to Avinoam! So I pushed it: http://hg.savannah.gnu.org/hgweb/octave/rev/db762b9b9b72.

Kai Torben Ohlhus <siko1056>
Group Member
Thu 22 Sep 2016 11:20:39 AM UTC, comment #2: 

Thanks Avinoam, patch works fine here AFAICS.

Philip Nienhuis <philipnienhuis>
Group Member
Tue 20 Sep 2016 05:37:25 PM UTC, comment #1: 

A patch attached which
1. fixes this bug
2. add demo
3. allow 5 input parameters, but issue a warning in this case (and not an error). see bug #43768

(file #38572)

Avinoam Kalma <avinoam>
Group Member
Tue 20 Sep 2016 05:33:54 PM UTC, original submission:  

As @Philip noticed in bug #43786


>> inputdlg ("prompt", "name", [1 40]);
error: inputdlg: ROWSCOLS vector does not match size of PROMPT
error: called from
    inputdlg at line 124 column 7


the patch will be in comment #1

Avinoam Kalma <avinoam>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #38572:  inpultdlg.cs added by avinoam (3KiB - 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 nrjank (Posted a comment)
  • -email is unavailable- added by dastew (Posted a comment)
  • -email is unavailable- added by coleman (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by avinoam (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 15 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-09-15 nrjank Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        StatusConfirmed Postponed
    2022-09-14 nrjank Assigned tosiko1056 None
    2022-09-14 nrjank Item GroupIncorrect Result Matlab Compatibility
    2022-09-14 nrjank StatusFixed Confirmed
        Open/ClosedClosed Open
        Release4.2.0-rc1 dev
        Summaryinputdlg does not handle well vectors inputdlg processes 2 element row vector rowscols input as heights instead of height and width
    2016-09-23 siko1056 Assigned toNone siko1056
    2016-09-23 siko1056 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2016-09-22 philipnienhuis StatusPatch Submitted Ready For Test
    2016-09-22 siko1056 StatusNone Patch Submitted
    2016-09-20 avinoam Attached File- Added inpultdlg.cs, #38572

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code