Why does INPUT interpret negative numbers as strings when compiled with MATLAB Compiler 4.0 (R14)?

5 次查看(过去 30 天)
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

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2023-4-16
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 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by