Matlab compiler: interactive input like INPUT function

조회 수: 6 (최근 30일)
Edward
Edward 2012년 5월 15일
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월 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일
please tell me how it can be passed in as command line options,i have the same problem
  댓글 수: 5
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일
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월 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

댓글을 달려면 로그인하십시오.

카테고리

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