![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/703367/image.jpeg)
Application compiler: How do I pass a file as Command line Input type argument
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Deepa Maheshvare
il 4 Ago 2021
Commentato: Deepa Maheshvare
il 20 Ago 2021
I am using Application compiler for generating a standalone application. I'm following the documenttaion available here
Example,
function m = magicsquare(n)
if ischar(n)
n=str2double(n);
end
m = magic(n);
disp(m)
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?
0 Commenti
Risposta accettata
Kojiro Saito
il 5 Ago 2021
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);
disp(t)
else
error('File not found')
end
end
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/703367/image.jpeg)
6 Commenti
Walter Roberson
il 16 Ago 2021
Current versions of readtable() also support URLs; https://www.mathworks.com/help/matlab/ref/readtable.html#btx_238-1_sep_mw_0c943b7b-3930-4683-b320-a361b8774ece
load() of a .mat file supports URLs but only for -v7.3 files, not for -v7 or -v5 .mat files.
The ability of readtable() to support URLs has been very convenient here on MATLAB Answers; the volunteers can now refer directly to the poster's attached file, instead of having to download the file and upload it to attach it to their own post.
Più risposte (1)
Image Analyst
il 16 Ago 2021
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)
0 Commenti
Vedere anche
Categorie
Scopri di più su MATLAB Compiler in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!