Borrar filtros
Borrar filtros

Use publish() with input variables for function with input object

12 visualizaciones (últimos 30 días)
Kevin Lebras
Kevin Lebras el 6 de Abr. de 2023
Respondida: Sachin el 10 de Abr. de 2023
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."

Respuestas (1)

Sachin
Sachin el 10 de Abr. de 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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by