# HG changeset patch # User Avinoam # Date 1474392650 -10800 # Tue Sep 20 20:30:50 2016 +0300 # Node ID 7c0618dd17078a50fa386a7a9c0bca6abf88bc28 # Parent 7ccbc2a6b99d8cb43b994a9b9226debff5273819 inputdlg: fix handling of rawcols vector (bug#49143) *inputdlg: fix handling of rawcols vector by chekcing ismatrix first add a suitable demo allow 5 parameters, and issue a warning in thie case diff -r 7ccbc2a6b99d -r 7c0618dd1707 scripts/gui/inputdlg.m --- a/scripts/gui/inputdlg.m Tue Sep 20 12:22:24 2016 -0400 +++ b/scripts/gui/inputdlg.m Tue Sep 20 20:30:50 2016 +0300 @@ -67,7 +67,7 @@ function cstr = inputdlg (prompt, varargin) - narginchk (1, 4); + narginchk (1, 5); if (iscell (prompt)) ## Silently extract only char elements @@ -95,7 +95,11 @@ if (nargin > 3) defaults = varargin{3}; endif - + + if (nargin > 4) + warning ("inputdlg: 5th 'options' argument ignored"); + endif + ## specification of text field sizes as in Matlab ## Matlab requires a matrix for linespec, not a cell array... ## rc = [1,10; 2,20; 3,30]; @@ -113,20 +117,20 @@ ## cols rowscols(:,2) = 25; rowscols(:,1) = linespec; - elseif (isvector (linespec)) - if (numel (linespec) == numel (prompt)) - ## only one column in lineTo, copy from vector linespec and add defaults - rowscols = zeros (numel (prompt), 2); - ## rows from colum vector linespec, columns are set to default - rowscols(:,2) = 25; - rowscols(:,1) = linespec(:); - else - error ("inputdlg: ROWSCOLS vector does not match size of PROMPT"); - endif elseif (ismatrix (linespec)) if (rows (linespec) == columns (prompt) && columns (linespec) == 2) ## (rows x columns) match, copy array linespec rowscols = linespec; + elseif (isvector (linespec)) + if (numel (linespec) == numel (prompt)) + ## only one column in lineTo, copy from vector linespec and add defaults + rowscols = zeros (numel (prompt), 2); + ## rows from colum vector linespec, columns are set to default + rowscols(:,2) = 25; + rowscols(:,1) = linespec(:); + else + error ("inputdlg: ROWSCOLS vector does not match size of PROMPT"); + endif else error ("inputdlg: ROWSCOLS matrix does not match size of PROMPT"); endif @@ -214,6 +218,18 @@ %! volume, surface), 'Box Dimensions'); %! endif +%!demo +%! disp ('- test inputdlg with vector for a single item.'); +%! prompt = {'enter x value'}; +%! default = {1}; +%! answer = inputdlg (prompt,'Enter value', [1 10], default); +%! if (isempty (answer)) +%! helpdlg ('Canceled by user', 'Information'); +%! else +%! helpdlg (sprintf ('answer = %d', str2num(answer{1})), 'answer'); +%! endif + +%!error inputdlg (1, 2, 3, 4, 5, 6) %!error inputdlg (1, 2, 3, 4, 5) %!error inputdlg (1) %!error inputdlg ("msg", 1)