필터 지우기
필터 지우기

Left and Right side have different elements

조회 수: 2 (최근 30일)
Anabelle
Anabelle 2024년 4월 17일
답변: Torsten 2024년 4월 17일
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;

답변 (2개)

Star Strider
Star Strider 2024년 4월 17일
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
v_theta = 1x401
10.9956 10.9283 10.8372 10.7236 10.5890 10.4352 10.2645 10.0790 9.8812 9.6737 9.4590 9.2398 9.0186 8.7979 8.5801 8.3676 8.1625 7.9667 7.7820 7.6099 7.4517 7.3085 7.1812 7.0702 6.9760 6.8986 6.8381 6.7940 6.7659 6.7532
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(t, v_theta)
grid
xlabel('t')
ylabel('v\_theta')
.

Torsten
Torsten 2024년 4월 17일
Replace t by t(i) in the loop.

카테고리

Help CenterFile Exchange에서 Robotics에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by