MATLAB 说我的等号两边的矩阵大小不相等

MATLAB says my matrices on both side of equal sign are not equal in size

提问人:Faito Dayo 提问时间:11/14/2022 最后编辑:beakerFaito Dayo 更新时间:11/14/2022 访问量:37

问:

这是我的代码

syms xi eta
    N1 = ((1+xi)*(1+eta))/4;
    N2 = ((1-xi)*(1+eta))/4;
    N3 = ((1-xi)*(1-eta))/4;
    N4 = ((1+xi)*(1-eta))/4;
    Nxieta = [N1 N2 N3 N4];
    difNxieta = sym(zeros(2,4))
    for i = 1:4
        difNxieta(1,i) = diff(Nxieta(1:i),xi);
        difNxieta(2,i) = diff(Nxieta(1:i),eta);
    end

这是它向我展示的错误

Unable to perform assignment because the size of the left side is 1-by-1 and the
size of the right side is 1-by-2.

Error in sym/privsubsasgn (line 1128)
                L_tilde2 =
                builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);

Error in sym/subsasgn (line 965)
            C = privsubsasgn(L,R,inds{:});

Error in Ae420_FEA_project>localstiffnessmatrix (line 55)
        difNxieta(1,i) = diff(Nxieta(1:i),xi);

但我不明白。diff(Nxieta(i:1),习) 不是数组。

MATLAB 矩阵 相等

评论

1赞 BillBokeey 11/14/2022
如果你在这一行上放一个断点,然后赋值给一个临时变量,它给你什么?diff(Nxieta(1:i),xi)
0赞 Faito Dayo 11/14/2022
temp = eta/4 + 1/4,但这是一回事,而不是 2 元素向量
1赞 BillBokeey 11/14/2022
这仅适用于循环中的第一次迭代。在第二次迭代中,你会得到[eta/4 + 1/4, - eta/4 - 1/4]
1赞 Ben Voigt 11/14/2022
dbstop if error是你的朋友

答: 暂无答案