'run' command with input argument - MATLAB 2018a

50 ビュー (過去 30 日間)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2020 年 3 月 20 日
編集済み: Stephen23 2020 年 3 月 20 日
I have Matlab script already existing in matlab path for example 'data_work_path'.
'data_work_path' function supports one input argument
I am going to call the above script from another script,
I will be getting the script name as string,
for example a = 'data', b = 'work', c = 'path'
run command woking when without input argument run([a, '_', b, '_', c])
but with input argument as string i am getting the error run([a, '_', b, '_', c, '(''alpha'')'])
can anyone help me?
Thanks in advance
  1 件のコメント
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2020 年 3 月 20 日
Error using run (line 55)
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax
error. To construct matrices, use brackets instead of parentheses.

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

採用された回答

Stephen23
Stephen23 2020 年 3 月 20 日
編集済み: Stephen23 2020 年 3 月 20 日
run does not work with functions, it only works with scripts:
If you want to call a function with some dynamic name, then you can use str2func like this:
str = sprintf('%s_%s_%s',a,b,c);
fun = str2func(str);
fun("alpha") % call it with whatever input arguments it requires.
Of course the function will need to be on the MATLAB Search Path or in the current directory.
  2 件のコメント
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2020 年 3 月 20 日
sorry i need to call the another script only
Stephen23
Stephen23 2020 年 3 月 20 日
編集済み: Stephen23 2020 年 3 月 20 日
"sorry i need to call the another script only"
All of your screenshots clearly show that data_work_path is a function. You cannot call it with run.
run only works with scripts.
run does not call functions.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by