# Left and Right side have different elements

4 ビュー (過去 30 日間)
Anabelle 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 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')
.
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

Torsten 2024 年 4 月 17 日
Replace t by t(i) in the loop.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeRobotics についてさらに検索

R2024a

### Community Treasure Hunt

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

Start Hunting!

Translated by