フィルターのクリア

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
  1 件のコメント
Mudit Garg
Mudit Garg 2024 年 6 月 7 日
Thank you @Matlab Pro for sharing a potential workaround.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet 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