no standalone apps output in console

I have function:
function m = magicsquare1(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
>> magicsquare1(5)
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
The standalone application is created by
>> mcc -mv magicsquare1.m (of course MCR is properly installed and configured)
Then the standalone application "magicsquare1" does not produce any output in command-line console!!! But it should, according to the help page of MATLAB compiler.
When I change the function like this:
function m = magicsquare2(n)
%MAGICSQUARE generates a magic square matrix of the size
% specified by the input parameter n.
% Copyright 2003-2012 The MathWorks, Inc.
if ischar(n)
n=str2num(n);
end
m = magic(n);
disp(m);
and recompile by
>>mcc -mv magicsquare2.m
I am able to get correct output.
>> !magicsquare2 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
So my question is: what is wrong? Why I am not able to get output from standalone application magicsquare1?

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2013년 2월 4일

5 개 추천

Executables in general cannot return a value, which explains what you're seeing. In MATLAB, when you call a function without a semicolon, it echoes the result of the command and also stores the returned value in a variable called ans, which is what happens when you run the function from the MATLAB command window.
If you'd like the executable to simply print the value to console, then use the DISP command as your figured out. If you'd like the value to be truly returned as a variable, you will need to generated a shared library from the MATLAB code instead of an executable.

댓글 수: 4

Michal Kvasnicka
Michal Kvasnicka 2013년 2월 4일
편집: Michal Kvasnicka 2013년 2월 4일
Your explanation is in conflict with official help: http://www.mathworks.com/help/pdf_doc/compiler/compiler.pdf (see page 1-16 and 1-22)
Michal Kvasnicka
Michal Kvasnicka 2013년 2월 7일
After one week I did not get any meaningful reaction on inconsistent MATLAB Compiler help problem. Just great!!??
Kaustubha Govind
Kaustubha Govind 2013년 2월 14일
편집: Kaustubha Govind 2013년 2월 14일
Michal: Please note that participation on this forum is entirely voluntary, and all contributors do so in their spare time. For urgent/important matters, you need to contact MathWorks Technical Support.
Coming back to your question - I don't know if what is in the documentation is an error. I would recommend that you report this as a bug to MathWorks Technical Support. Thanks!
Benjamin Thompson
Benjamin Thompson 2024년 6월 15일
So what is the recommended workaround for sending output to the console from a MATLAB function when MATLAB Coder is used to generated C/C++ code for that function? The documentation does state that disp is not supported for generated code.

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

카테고리

도움말 센터File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

질문:

2013년 2월 1일

댓글:

2024년 6월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by