Use publish() with input variables for function with input object
8 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I want to use the publish() call with a function that has an input object. The only documentation I can find allows you to have a numerical input but not a variable input. This example is given in the documentation
publish('fact.m','codeToEvaluate','fact(5);')
web('html/fact.html')
I want to run the same function but replace "5" with an input variable "x". Is there a way to accomplish this?
x=5
publish('fact.m','codeToEvaluate','fact(x);')
web('html/fact.html')
If I run the above example I get the following warning
"Error using evalin
Argument must be a text scalar."
0 件のコメント
回答 (1 件)
Sachin
2023 年 4 月 10 日
Hi
I understand that you want to use publish() function with a variable name so this workaround might be of good help to you.
You use string concatenation to create the string with the fact() function that can be passed as a third argument to the publish function.
x = 5;
codeToEvaluate = ['fact(', num2str(x), ');'];
publish('fact.m', 'codeToEvaluate', codeToEvaluate);
web('html/fact.html');
In the above code, we are creating the string “codeToEvaluate” that includes the value of x with function fact().
Thanks
Sachin
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!