Application compiler: How do I pass a file as Command line Input type argument

조회 수: 29(최근 30일)
I am using Application compiler for generating a standalone application. I'm following the documenttaion available here
function m = magicsquare(n)
if ischar(n)
m = magic(n);
On the command line, I do !magicsquare 5, to run the executable.
But when I want to pass a file (e.g excel or json file) as an input argument while running the executable generated for my use case, how do I pass an input file?

채택된 답변

Kojiro Saito
Kojiro Saito 2021년 8월 5일
File object itself cannot pass in command line, but you can pass file path.
Below is a sample code.
function myFileOpenTest(inputFileName)
result = isfile(inputFileName);
if result
t = readtable(inputFileName);
error('File not found')
You can run the exe with file name as an input argument.
myFileOpenTest.exe myData.xlsx
By default, standalone application does not show disp result in Command Prompt, so you need to uncheck the following option.
  댓글 수: 6

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

추가 답변(1개)

Image Analyst
Image Analyst 2021년 8월 16일
You need to wrap your filename in single or double quotes, expecially if there is a space, otherwise it will think you're passing two arguments. You should be able to do
!magicsquare("c:/users/Deepa/my data.xlsx"); % Run the .exe file (not the m-file)


Find more on Application Deployment in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by