How can I make correct executable file?

I made an executable file from my code below.
mcc -m test_yli.m
My code:
#
function b = test_yli(a)
if ischar(a)
a = str2num(a);
end
b=a+1;
disp(b)
disp('code stop here')
Then I run
#
[status result] = system('"test_yli.exe" "1"')
But the returned value are
status =
0
result =
2
code stop here
But I simply want to get the returned b=2. If I delete the two disp() command in my -m code for making the executable file, then my returned value (e.g. retult) is empty!
status =
0
result =
''
Can anyone please tell me where I'm wrong? Many thanks in advance!

回答(1 个)

Steven Lord
Steven Lord 2018-6-25
From the "Using a MATLAB File You Plan to Deploy" section on this documentation page: "You cannot return values from your standalone application to the user. The only way to return values from compiled code is to either display it on the screen or store it in a file."
Remember, MATLAB isn't running your application. Your operating system is, and your operating system has no notion of how a MATLAB variable should be stored in memory if it were to be returned from your application.

此问题已关闭。

标签

提问:

2018-6-25

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by