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
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
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
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
Edward 2012 年 5 月 17 日
How do you use standard input (0)?
I have been able to use standard output by doing fwrite(1,etc..)
fread(0,...) doesn't work

サインインしてコメントする。

回答 (2 件)

Ahmed Saad
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
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
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
Walter Roberson 2012 年 5 月 15 日
Quick example:
function YourMainFunction(varargin)
if nargin >= 1
firstarg = str2double(varargin{1});
else
firstarg = [];
end
Ahmed Saad
Ahmed Saad 2012 年 5 月 15 日
i did not get it work but thank you for your kind reply
Edward
Edward 2012 年 5 月 17 日
Ahmed - try this:
1) Make the following matlab function as usual:
function boob(a,b)
if ischar(a)
aa=str2num(a);
else
aa=a;
end
if ischar(b)
bb=str2num(b);
else
bb=b;
end
v = aa + bb;
fprintf('The answer is: %i \n',v)
end
2) Compile with the Matlab compiler
3) Run from a (windows) command line:
boob.exe 5 8
4) obtain:
The answer is: 13

サインインしてコメントする。

Edward
Edward 2012 年 5 月 17 日

0 投票

Thanks Walt
I am compiling a standalone executable, running from the windows command terminal. For example:
function input_test1(a)
fprintf('Input argument is: %s \n',a)
x = input('Please input a letter... ','s');
fprintf('\nYou typed: %s \n\n',x)
end
This compiles and runs fine, up to the point where you input the letter. It then gives the error:
'y' is not recognized as an internal or external command, operable program or batch file.
(where y is the actual letter typed). Am I doing something wrong here?
In Mex files I have found that you can use the input function with mexCallMATLAB, so maybe that is the way to go. Seems inconvenient though.
Not sure how to use standard input.

4 件のコメント

Kaustubha Govind
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
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
Kaustubha Govind 2012 年 5 月 22 日
Ah. That makes sense.
Amro
Amro 2013 年 5 月 29 日
編集済み: Amro 2013 年 5 月 29 日
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 ExchangeMATLAB Compiler についてさらに検索

質問済み:

2012 年 5 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by