How to call a function with arguments containing "." in "run" function?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mudit Garg
el 6 de Jun. de 2024
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1710231/image.png)
But, If version number has decimal, it trys to find the whole string as a script.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1710236/image.png)
Thank you.
1 comentario
Stephen23
el 7 de Jun. de 2024
Editada: Stephen23
el 7 de Jun. de 2024
"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.
Respuesta aceptada
Matlab Pro
el 6 de Jun. de 2024
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!