필터 지우기
필터 지우기

How to call a function with arguments containing "." in "run" function?

조회 수: 4 (최근 30일)
Mudit Garg
Mudit Garg 2024년 6월 6일
편집: Stephen23 2024년 6월 7일
Lets say I am trying to call a function called printVersion() using run.
Here is printVersion()
function printVersion(version)
disp(version)
end
Now, if version number doesn't contain decimal, it works fine.
But, If version number has decimal, it trys to find the whole string as a script.
Thank you.
  댓글 수: 1
Stephen23
Stephen23 2024년 6월 7일
편집: Stephen23 2024년 6월 7일
"How to call a function with arguments containing "." in "run" function?"
Don't do this: RUN is only documented for scripts, not functions. Any other undocumented behavior RUN might have is liable to change or be unpredictable. Use function handles and avoid meta-programming in code.

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

채택된 답변

Matlab Pro
Matlab Pro 2024년 6월 6일
You are correct: Matlab tries to look for a program with this name.
A simple solution to overcome this issue is by doing an 'eval' command ahead and sending this eval var to the function
eval('a="Version1.1";');run('printVersion(a)')
function printVersion(version)
disp(version)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by