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