Matlab RunTime and argc/argv as input arguments of an app?

23 ビュー (過去 30 日間)
Eric Delgado
Eric Delgado 2022 年 9 月 14 日
編集済み: Chris 2022 年 11 月 9 日
I have two apps made on AppDesigner (desktop apps) and, for some reason, I want to generate separate executables files. In this context, I want to call one app from the other using the system command line.
So... I have two questions about it:
(1) Is it possible to open this new app in the same instance of Matlab RunTime (that is running the calling app)?
(2) Is it possible to read command line arguments (like argc and argv in C/C++) as input arguments of a desktop app made on AppDesigner?
  4 件のコメント
Eric Delgado
Eric Delgado 2022 年 10 月 6 日
Hi @Adam Danz, I am glad that you are here! :)
(1) Is it possible to open this new app in the same instance of Matlab RunTime (that is running the calling app)?
I still don't know if it is possible.
(2) Is it possible to read command line arguments (like argc and argv in C/C++) as input arguments of a desktop app made on AppDesigner?
I figured out two ways how to deal with it, but both are "bad solutions", I think.
  • Bad solution 1: I edited the list of the input variables of my app and called the app from the prompt, passing the strings (numerical or textual) as arguments. So far so good, BUT the process becomes "stuck" to the prompt, so if I close the prompt this will close my app too.
  • Bad solution 2: I pass the arguments to my app through a file, and its content is read in the startup of my app.
Adam Danz
Adam Danz 2022 年 10 月 6 日
Thanks, but in this case, I may not be that helpful as I've had very limited experience with deployable apps, it's just not my forte. I don't think what you're describing in you Q1 is possible. For your Q2, are you asking how to read the MATLAB-driven command line? diary is often used to read MATLAB command history and this could be an option as it is not listed as an excluded function in compiled apps.

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

採用された回答

Chris
Chris 2022 年 11 月 9 日
編集済み: Chris 2022 年 11 月 9 日
(1) Is it possible to open this new app in the same instance of Matlab RunTime (that is running the calling app)?
I agree, doesn't seem possible for an exe, but MathWorks might know otherwise (this is also not my forte).
(2) Is it possible to read command line arguments (like argc and argv in C/C++) as input arguments of a desktop app made on AppDesigner?
Tested in R2022a
In appdesigner, make a startupFcn callback and right-click on it. You can "Edit App Input Arguments."
My prototype startup function looks like this (and I've added the corresponding Properties "arg1" and "arg2"):
function startupFcn(app, arg1, arg2)
arguments
app
arg1 = 'Hi';
arg2 = 'Ho';
end
app.arg1 = arg1;
app.arg2 = arg2;
end
Setting default values for the arguments allows you to skip them at the command line.
varargin works for this too, but you need somewhere appropriate to stick the arguments. For instance:
function startupFcn(app, varargin)
app.argv = varargin;
end
in the startupFcn, with "argv" as an app property. Simple enough.
Compile the app to a standalone desktop app. In a terminal, you can invoke it with spaces between the arguments:
./appX.exe beep boop
In Matlab, wrap the command with system:
system('./appX.exe beep boop')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by