【问题标题】:Unable to perform assignment because the left and right sides have a different number of elements. MATLAB ERROR无法执行分配,因为左侧和右侧的元素数量不同。 MATLAB 错误
【发布时间】:2020-11-26 10:11:33
【问题描述】:

我尝试使用 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");

这是我的工作区: Workspace

【问题讨论】:

  • 问题是左边只有1个数字,而右边却是多1个数字。没有实际数据,我们无能为力。
  • 您需要哪些数据?
  • a minimal reproducible example,这是要求调试帮助的要求
  • 这是所有代码:pastebin.com/mgg9p9td
  • edit 发帖,并在仍然有效的情况下尽量减少代码

标签: matlab matrix variable-assignment


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    相关资源
    最近更新 更多