簡體   English   中英

無法執行分配,因為左側和右側的元素數量不同。 MATLAB 錯誤

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

我嘗試使用 MATLAB 計算一些矩陣。 運行此代碼后,我收到錯誤“無法執行分配,因為左側和右側的元素數量不同。” 經過簡單的調試,我得出結論,在注釋 X(j) 和 Y(j) 程序運行正確之后。 我看了一些類似的問題,但我找不到可以幫助我解決上述問題的東西

 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");

這是我的工作區:工作區

您在方程式末尾使用alpha2 ,這是一個向量。 你可能想要alpha2(j)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM