Matlab compiler: interactive input like INPUT function
Show older comments
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 Comments
Walter Roberson
on 15 May 2012
I wonder if fid 0 (standard input) and fid 1 (standard output) are connected usefully in a compiled routine?
Kaustubha Govind
on 16 May 2012
What is the error you get when compiling with the INPUT function? Also please mention what platform you are working on.
Walter Roberson
on 16 May 2012
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
on 17 May 2012
Answers (2)
Ahmed Saad
on 15 May 2012
0 votes
please tell me how it can be passed in as command line options,i have the same problem
5 Comments
Walter Roberson
on 15 May 2012
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
on 15 May 2012
thank you walter,but i still did not get it well .could you explain more,sorry i am still a beginner
Walter Roberson
on 15 May 2012
Quick example:
function YourMainFunction(varargin)
if nargin >= 1
firstarg = str2double(varargin{1});
else
firstarg = [];
end
Ahmed Saad
on 15 May 2012
i did not get it work but thank you for your kind reply
Edward
on 17 May 2012
Edward
on 17 May 2012
4 Comments
Kaustubha Govind
on 18 May 2012
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
on 18 May 2012
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
on 22 May 2012
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
Categories
Find more on MATLAB Compiler 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!