Can I run a matlab file with symbolic functions from the command line?

1 次查看(过去 30 天)
I am trying to run this file below with symbolic expresssions. It runs in the editor and it does output to the two files below with no errors.
A = [1 1 1 1 1 2 2; 1 3 2 6 4 2 6; 1 2 4 1 2 5 3; 1 6 1 6 1 5 2; 1 4 2 1 4 5 6; 1 5 4 6 2 4 6];
sym x_1;
sym x_2;
sym x_3;
sym x_4;
sym x_5;
sym x_6;
Q = [x_1 x_2 x_3 x_4 x_5 x_6 1];
solution = solve(A*Q.');
answer = [solution.x_1 solution.x_2 solution.x_3 solution.x_4 solution.x_5 solution.x_6 1];
answer = mod(answer, 7);
answer = answer*10;
answer = mod(answer, 7);
answer = double(answer);
check = mod(A*answer.',7);
check = double(check);
writematrix(answer, "test2.txt");
writematrix(check, "check.txt");
But when I try to run it from the command line using:
matlab -nodisplay -nosplash -nodesktop -r "run('C:\pathtofile\file.m');"
It returns an error saying that the variable x_1 does not exist. Does that mean symbolc expressions cannot work from the command line?

采纳的回答

Ridwan Alam
Ridwan Alam 2019-12-10
syms x_1;
syms x_2;
syms x_3;
syms x_4;
syms x_5;
syms x_6;
Hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by