Asterisk in MATLAB CLI Statements

2 次查看(过去 30 天)
Josh Zhang
Josh Zhang 2022-4-2
回答: Harshit 2023-9-15
When passing statements to MATLAB CLI, asterisk * will be parsed by the shell, as listing files in the directory, instead of being parsed by MATLAB as multiplication.
Example: in terminal run this command
matlab -nodesktop -nosplash -r "1 * 2"
The output is
1 file1 file2 file3 2
where file1, file2, file3 are the items in the current directory.
Is there a way to prevent shell from parsing the statements?

回答(1 个)

Harshit
Harshit 2023-9-15
Hi,
I understand that you want to run a MATLAB script after it starts using the startup options but facing an issue while passing a multiplication symbol as it is treated as a way of listing the directory instead of a math symbol.
The cause of this issue is a bit unclear as the statement works fine for the latest version of MATLAB on Windows. It would be helpful if you could share the version of MATLAB and the OS platform that you're using.
As a workaround, you can encapsulate the math expression inside the "eval" function of MATLAB. For example:
matlab -nodesktop -nosplash -r "eval('1 * 2');"
Please note that the "eval" function expects a string datatype for the input. Hence, the expression must be a string or character vector.
To learn more about the eval function, you can refer to the following document:
I hope this helps.
Regards,
Harshit

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by