Left and Right side have different elements
1 view (last 30 days)
Show older comments
For theta_dot(i) specifically, I keep running into the error "Unable to perform assignment because the left and right sides have a different number of elements". I'm amateur with MatLab and need help fixing that line.
t = 0:0.01:4; % Timesteps for robotic arm motion
for i = 1:length(t)
% Position of robotic arm in r-theta coordinates
theta(i) = -(pi/4)*t.^2+pi*t;
r(i) = 3+0.5*cos(4*theta(i));
% Position of robotic arm in x-y coordinates
x(i) = r(i)*cos(theta(i));
y(i) = r(i)*sin(theta(i));
% Velocity of robotic arm in radial/transverse components
theta_dot(i) = -(pi/2)*t+pi;
r_dot(i) = pi*sin(4*theta(i));
v_r(i) = r_dot(i);
v_theta(i) = (r(i)*theta_dot(i));
% Velocity of robotic arm in Cartesian coordinates
% v_x(i) = MODIFY;
% v_y(i) = MODIFY;
0 Comments
Answers (2)
Star Strider
on 17 Apr 2024
You need to subscript ‘t’.
Then, it works —
t = 0:0.01:4; % Timesteps for robotic arm motion
for i = 1:length(t)
% Position of robotic arm in r-theta coordinates
theta(i) = -(pi/4)*t(i).^2+pi*t(i); % <— Changed: 't' To 't(i)'
r(i) = 3+0.5*cos(4*theta(i));
% Position of robotic arm in x-y coordinates
x(i) = r(i)*cos(theta(i));
y(i) = r(i)*sin(theta(i));
% Velocity of robotic arm in radial/transverse components
theta_dot(i) = -(pi/2)*t(i)+pi; % <— Changed: 't' To 't(i)'
r_dot(i) = pi*sin(4*theta(i));
v_r(i) = r_dot(i);
v_theta(i) = (r(i)*theta_dot(i));
% Velocity of robotic arm in Cartesian coordinates
% v_x(i) = MODIFY;
% v_y(i) = MODIFY;
end
v_theta
figure
plot(t, v_theta)
grid
xlabel('t')
ylabel('v\_theta')
.
0 Comments
See Also
Categories
Find more on Robotics 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!