简体   繁体   中英

Unable to perform assignment because the left and right sides have a different number of elements. MATLAB ERROR

I try to compute a few matrices using MATLAB. After run this code I get a error "Unable to perform assignment because the left and right sides have a different number of elements." After simple debugging i get conclusion that after comment X(j) and Y(j) program run correctly. I looked on some similar problem but I cannot find sth that can help me with above problem

 clear all
close all
clc
%stale
a1 = 1;
a2 = 1;
a3 = 1;
a4 = 1;
a5 = 1;

%% Napęd 2
X=0; Y=0; Z=0;
th1 = 0; th2 = 0; th3 = 0; th4 = 0; th5 = 0;
%alfa2 = 1;
alfa2 = 0:(pi/12):(pi);
alfa1 = 0; alfa3 = 0; alfa4 = 0; alfa5 = 0;
d5=1; d4=1; d3=1; d2=1; d1=1;
a3 = 1;
a3 = 0.1:(1/14):1;
 
for j = 1 : length(alfa2)
    X(j) = a5*cos(th1)*cos(th4)*cos(th5) + a5*sin(th1)*sin(alfa2(j))*sin(th4)*cos(th5) - a5*cos(th1)*sin(th4)*sin(th5) + a5*sin(th1)*sin(alfa2(j))*cos(th4)*sin(th5) + d4*sin(th1)*cos(alfa2(j)) + a3*cos(th1) + alfa2*cos(th1);
 
    Y(j) = a5*sin(th1)*sin(th4)*cos(th5) - a5*cos(th1)*sin(alfa2(j))*cos(th4)*cos(th5) - a5*sin(th1)*sin(th4)*sin(th5) - a5*cos(th1)*sin(alfa2(j))*cos(th4)*sin(th5) + d4*sin(th1)*cos(alfa2(j)) + a3*cos(th1) + alfa2*cos(th1);
 
    Z(j) = a5*cos(alfa2(j))*sin(th4)*cos(th5) + a5*cos(alfa2(j))*cos(th4)*sin(th5) -d4*sin(alfa2(j)) + d1;
end
figure(1);
subplot(2, 2, 1); plot3(Y, X, Z); grid on; title("Przestrzen XYZ");
xlabel('y'); ylabel('X'); zlabel('Z')
subplot(2, 2, 2); plot(Y, X); grid on; xlabel('Y'); ylabel('X');
title("Plaszczyzna XY");
subplot(2, 2, 3); plot(X, Z); grid on; xlabel('X'); ylabel('Z');
title("Plaszczyzna XZ");
subplot(2, 2, 4); plot(Y, Z); grid on; xlabel('Y'); ylabel('Z');
title("Plaszczyzna YZ");

This is my workspace: Workspace

You are using alpha2 in the end of your equations, which is a vector. You likely want alpha2(j)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM