필터 지우기
필터 지우기

How to apply Command line arguments in matlab

조회 수: 370 (최근 30일)
Tal Markovitz
Tal Markovitz 2019년 4월 14일
댓글: Helen Zhu 2024년 6월 12일
Hi,
I have matlab function that I want to use with different input file in every run.
Also, I want to convert it to exe file and run the script standalone from matlab.
Any Ideas how to do this?
  댓글 수: 1
Helen Zhu
Helen Zhu 2024년 6월 12일
Hi Tal,
Does the answer provided by Yash answer your question?
Or do you have a different workflow?

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

답변 (2개)

Yash Totla
Yash Totla 2019년 6월 24일
The MATLAB website has a worked-through example with instructions on how to compile a simple application and how to deploy it on another computer. In essence, you need to install the MATLAB Compiler Runtime together with your application. The installer for the runtime should already be present in your MATLAB compiler installation.
To pass command-line arguments to a MATLAB executable, you define a single MATLAB function in the executable. The arguments to the function are taken from the command line parameters (the first command-line parameter is the first argument, and so on).
For example, create a file
echo.m
with the following contents:
function exitcode = echo(a,b)
display(a)
display(b)
exitcode = 0;
end
You can then compile this file and run it with
echo 1 2 3
and it will print
a=1 b=2

Image Analyst
Image Analyst 2019년 5월 25일
Read up on how to use varargin(). Pull the command line words out of varargin.
  댓글 수: 2
Serena Ghantous Lotreck
Serena Ghantous Lotreck 2020년 2월 24일
As far as I've been able to tell, vargin() is just used for writing functions that can take a variable number of input arguments; I haven't found anything on how to use this to pull words from command line input arguments.
I'm running my code as
matlab -nodisplay -r "myFile"
and want to be able to input two file paths and a number as command line arguments.
Image Analyst
Image Analyst 2020년 2월 24일
You need to use the name of your m-file, not "matlab -nodisplay". For example
myapp "C:\user\Serena\Documents\your data folder"

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

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by