My for loop gives an error
1 view (last 30 days)
Show older comments
alpha=sym('alpha',[1 6])
theta=sym('theta',[1 6])
d=sym('d',[1 6])
a=sym('a',[1 6])
A=sym('A',[1 6])
for S=[1 2 3 4 5 6]
A(S)=[cos(theta(S)),-sin(theta(S))*cos(alpha(S)),sin(theta(S))*sin(alpha(S)),a(S)*cos(theta(S))
sin(theta(S)),cos(theta(S))*cos(alpha(S)),-cos(theta(S))*sin(alpha(S)),a(S)*sin(theta(S))
0,sin(alpha(S)),cos(alpha(S)),d(S)
0,0,0,1]
end
My answer is as follows
>> NEW
alpha =
[ alpha1, alpha2, alpha3, alpha4, alpha5, alpha6]
theta =
[ theta1, theta2, theta3, theta4, theta5, theta6]
d =
[ d1, d2, d3, d4, d5, d6]
a =
[ a1, a2, a3, a4, a5, a6]
A =
[ A1, A2, A3, A4, A5, A6]
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in sym/privsubsasgn (line 1067)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 904)
C = privsubsasgn(L,R,inds{:});
Error in NEW (line 7)
A(S)=[cos(theta(S)),-sin(theta(S))*cos(alpha(S)),sin(theta(S))*sin(alpha(S)),a(S)*cos(theta(S))
0 Comments
Accepted Answer
Luna
on 27 Mar 2019
Edited: Luna
on 27 Mar 2019
You can put your symbolic 4x4 matrices into a cell array.
Also your for loop is wrongly defined like for S = [1 2 3...]. You should define for S from 1 to 6.
alpha=sym('alpha',[1 6])
theta=sym('theta',[1 6])
d=sym('d',[1 6])
a=sym('a',[1 6])
% A=sym('A',[1 6])
A_new = cell(1,6); % preallocation of cell array
for S = 1:6
A_new{S} = [cos(theta(S)),-sin(theta(S))*cos(alpha(S)),sin(theta(S))*sin(alpha(S)),a(S)*cos(theta(S))
sin(theta(S)),cos(theta(S))*cos(alpha(S)),-cos(theta(S))*sin(alpha(S)),a(S)*sin(theta(S))
0,sin(alpha(S)),cos(alpha(S)),d(S)
0,0,0,1]
end
So whenever you want to reach them individually you can type:
A_new{1}
it gives the result for 1st 4x4 matrix as follows:
>> A_new{1}
ans =
[ cos(theta1), -cos(alpha1)*sin(theta1), sin(alpha1)*sin(theta1), a1*cos(theta1)]
[ sin(theta1), cos(alpha1)*cos(theta1), -sin(alpha1)*cos(theta1), a1*sin(theta1)]
[ 0, sin(alpha1), cos(alpha1), d1]
[ 0, 0, 0, 1]
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!