Matlab compiler: interactive input like INPUT function
显示 更早的评论
When making compiled programs with the Matlab compiler, is there a way of accepting variables from the user after the program has started running?
I know that variables can be passed in as command line options when executing the program.
But I want to use something like the Matlab INPUT command (this causes an error)
Thanks.
4 个评论
Walter Roberson
2012-5-15
I wonder if fid 0 (standard input) and fid 1 (standard output) are connected usefully in a compiled routine?
Kaustubha Govind
2012-5-16
What is the error you get when compiling with the INPUT function? Also please mention what platform you are working on.
Walter Roberson
2012-5-16
If windows, is it a console application or a standalone application that you are producing? It would not surprise me if input() failed on a standalone application.
Edward
2012-5-17
回答(2 个)
Ahmed Saad
2012-5-15
0 个投票
please tell me how it can be passed in as command line options,i have the same problem
5 个评论
Walter Roberson
2012-5-15
The top level routine you compile must be a function (a compiler restriction). That function can have arguments. Anything typed on the command line that is not grabbed by the operating system, will be passed in as arguments to the function, as strings (NOT as numeric values!)
Ahmed Saad
2012-5-15
thank you walter,but i still did not get it well .could you explain more,sorry i am still a beginner
Walter Roberson
2012-5-15
Quick example:
function YourMainFunction(varargin)
if nargin >= 1
firstarg = str2double(varargin{1});
else
firstarg = [];
end
Ahmed Saad
2012-5-15
i did not get it work but thank you for your kind reply
Edward
2012-5-17
Edward
2012-5-17
4 个评论
Kaustubha Govind
2012-5-18
Strange - it looks like the entered value is getting evaluated. I wonder if input('Please input a letter... ','s') is being treated like input('Please input a letter... ') in deployed mode. What happens if you input the name of a MATLAB function like 'rand' instead of 'y'.
Walter Roberson
2012-5-18
That isn't it, Kaustubha. The error being generated is from MS Windows -- the input is going to CMD not to the program. MATLAB would complain about no routine named "y" but would not complain about it not being a batch file.
Kaustubha Govind
2012-5-22
Ah. That makes sense.
if you want this to work, you must choose "console application" NOT "windows standalone application" from the deploytool dialog. This is equivalent to compiling as:
mcc -W main -T link:exe myfunc.m
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Compiler 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!