Why does INPUT interpret negative numbers as strings when compiled with MATLAB Compiler 4.0 (R14)?
3 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 16 Apr 2023
I used INPUT to prompt the user for arguments to pass into my function. When run inside MATLAB, both positive numbers and negative numbers are interpreted as double-precision matrices inside of the function. However, when I compile the function and run it in stand-alone mode, positive numbers are interpreted as matrices, but negative numbers are interpreted as strings. The following function reproduces this behavior:
function inputtest
y=input('Enter a number: ');
if ischar(y)
disp('Number interpreted as string');
elseif isnumeric(y)
disp('Number interpreted as matrix');
end
Accepted Answer
MathWorks Support Team
on 20 Feb 2023
Edited: MathWorks Support Team
on 16 Apr 2023
This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
We have verified a bug in MATLAB Compiler 4.0 (R14) in the way that INPUT handles negative numbers as inputs when executed in stand-alone mode. To work around this issue, try testing the input to see if it is interpreted as a matrix or a string. If it is interpreted as a string but you know that it should be a number, use STR2NUM to convert it.
You might also consider using a different method for passing input arguments to the function. For example, try using the INPUTDLG function to prompt for inputs in a dialog box or create a graphical user interface for your function.
For more details on how to pass arguments to compiled functions, see the following solution:
0 Comments
More Answers (0)
See Also
Categories
Find more on String in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!