首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法执行赋值,因为左侧和右侧的元素数量不同。MATLAB错误

无法执行赋值,因为左侧和右侧的元素数量不同。MATLAB错误
EN

Stack Overflow用户
提问于 2020-11-26 18:11:33
回答 1查看 1.5K关注 0票数 0

我试着用MATLAB计算几个矩阵。运行这段代码后,我得到一个错误消息:"Unable to perform assignment,因为左侧和右侧的元素数量不同。“经过简单的调试,我得到的结论是,在注释X(j)和Y(j)之后,程序运行正常。我看过一些类似的问题,但我找不到能帮助我解决上述问题的东西。

代码语言:javascript
复制
 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");

这是我的工作区:Workspace

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-26 18:34:30

您在方程式的末尾使用了alpha2,它是一个向量。您可能需要alpha2(j)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65019910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档