我想使用subs()在单元格数组“ Ti”中完成一系列替换,但是不能这样做,因为如果“ Ti”不是一个符号,则subs()会发布错误。
运行以下脚本:
n = 7;
q = sym('q', [n 1], 'real');
x = sym('x', [n 1], 'real');
d = sym('d', [n 1], 'real');
a = sym('a', [n 1], 'real');
syms a1 I real
q0 = [0 3*pi/2 0 pi 0 pi 3*pi/2];
d0 = [317 192.5 400 168.5 400 136.3 133.75];
x0 = [-pi/2 -pi/2 -pi/2 -pi/2 -pi/2 -pi/2 0];
a0 = [81 0 0 0 0 0 0];
I0 = 1;
Ti = cell(n+1,1);
Ti(1) = {[1 0 0 0;0 1 0 0; 0 0 1 0; 0 0 0 1]};
for i = 2:n+1
Ti{i} = Ti{i-1} * ([cos(q(i-1)) -sin(q(i-1)) 0 0; sin(q(i-1)) cos(q(i-1)) 0 0; 0 0 1 0; 0 0 0 1] *[1 0 0 0; 0 1 0 0; 0 0 1 d(i-1); 0 0 0 1]*[1 0 0 a(i-1); 0 1 0 0; 0 0 1 0; 0 0 0 1]*[1 0 0 0; 0 cos(x(i-1)) -sin(x(i-1)) 0 ; 0 sin(x(i-1)) cos(x(i-1)) 0; 0 0 0 1]);
end
Ti = {Ti(2:8 , 1)};
Ti = subs(Ti, x, x0.');
Ti = subs(Ti, a(2:n), a0(2:n).');
Ti = subs(Ti, a(1), 'a1');
Ti_c = cell (n,1);
for k = 1:n
Ti_c{k} = Ti(4*k-3:4*k,1:4);
end
Ti = cell(n,1);
Ti = Ti_c;
我收到以下错误:
Error using subs
Expected input number 1, S, to be one of these types:
sym
Instead its type was cell.
Error in sym/subs (line 60)
validateattributes(F, {'sym'}, {}, 'subs', 'S', 1);
Error in transforms (line 23)
Ti = subs(Ti, x, x0.');
此行的预期结果是将单元格Ti中x0的转置置换为x。实际结果是一个错误,因为Ti是一个单元格数组而不是一个符号。