Use publish() with input variables for function with input object
8 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Sachin
on 10 Apr 2023
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 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!