简体   繁体   English

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

[英]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.我尝试使用 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.经过简单的调试,我得出结论,在注释 X(j) 和 Y(j) 程序运行正确之后。 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.您在方程式末尾使用alpha2 ,这是一个向量。 You likely want alpha2(j)你可能想要alpha2(j)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Matlab:无法执行赋值,因为左侧和右侧的元素数量不同 - Matlab: Unable to perform assignment because the left and right sides have a different number of elements 无法执行分配,因为左侧和右侧具有不同数量的元素 - Unable to perform assignment because the left and right sides have a different number of elements 左侧和右侧具有不同数量的元素 - Left and right sides have a different number of elements 尝试定义周期信号的条件时,左侧和右侧具有不同数量的元素 - Left and right sides have a different number of elements when trying to define conditions of a periodic signal 由于左侧的索引与右侧的大小不兼容,无法执行分配 - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side 无法执行分配,因为左侧的大小为 1×2,右侧的大小为 2×2 - Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 2-by-2 无法执行分配,因为左侧的索引与右侧的大小不兼容。 这是什么意思? - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. What does this mean? 无法执行分配,因为左侧的索引与右侧的大小不兼容。? - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.? 我在 matlab_Index 中收到此错误,超出了数组元素的数量。 索引不得超过 1 - I am getting this error in matlab_Index exceeds the number of array elements. Index must not exceed 1 我不断收到此错误消息无法执行分配,因为“tf”类型的值不可转换为“单元格”? - I keep get this error message Unable to perform assignment because value of type 'tf' is not convertible to 'cell'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM