# MATLAB: Error when calling a function : “Dimensions of arrays being concatenated are not consistent.”

MATLABmatlab functionprofound analysis

Hey guys and girls ðŸ™‚
I am writing a Code for Finite Element calculation on beams.
``function y = fun_BeamFrameStiff2D(E,A,I,cosa,sina,len)    b1 = A*cosa^2 + 12*I*sina^2/len^2;    b2 = A*sina^2 + 12*I*cosa^2/len^2;    b3 = (A-12*I/len^2)*cosa*sina;    b4 = 6*I*sina/len;    b5 = 6*I*cosa/len;        y = E/len*[b1 b3 -b4 -b1 - b3 -b4; b3 b2 b5 -b3 -b2 b5;...              -b4 b5 4*I b4 -b5 2*I; -b1 -b3 b4 b1 b3 b4;...              -b3 -b2 -b5 b3 b2 -b5; -b4 b5 2*I b4 -b5 4*I]E=1;A=1;I=1;% Abfrage der Koordinaten der Elementeelements=input('Anzahl der Elemente')sysnodes=input('Anzahl der Systemknoten')nodes=zeros(sysnodes,2);cords=zeros(2*elements,2);for p=1:sysnodes    nodes(p,1)=input('Systemstartknoten des Element:')    nodes(p,2)=input('Systemendknoten des Element:')endfor p=1:2*elements    cords(p,1)=input('x-Koordinate des Knotens i von Element i :')    cords(p,2)=input('y-Koordinate des Knotens i von Element i :')endlenx=zeros(elements,1);leny=zeros(elements,1);len=zeros(elements,1);for p=1:elements    for q=1:2:2*elements-1        lenx(p)=cords(q+1,1)-cords(q,1)        leny(p)=cords(q+1,2)-cords(q,2)        len(p)=sqrt(lenx(p)^2+leny(p)^2)    endendsina=zeros(elements);cosa=zeros(elements);for p=1:elements    sina(p)=leny(p)/len(p);    cosa(p)=lenx(p)/len(p);endk1=fun_BeamFrameStiff2D(E,A,I,cosa(1),sina(1),len(1))``
When I try to call the function, I always get the error mentioned in the title – whats wrong about this?
I thought about changing the inputs to cosa(elements), sina(elements)…. but then when I tried I got the error "invalid expression. when calling a function or indexing a variable, use parentheses. otherwise check for mismatched delimiters."

``Error using vertcatDimensions of matrices being concatenated are not consistent.Error in fun_BeamFrameStiff2D (line 8)    y = E/len*[b1 b3 -b4 -b1 - b3 -b4; b3 b2 b5 -b3 -b2 b5;... ``
``    y = E/len*[b1 b3 -b4 -b1 - b3 -b4; b3 b2 b5 -b3 -b2 b5;...    %                        ^ this is a binary operator on -b1 and b3, NOT a unary operator on b3``
``function y = fun_BeamFrameStiff2D(E,A,I,cosa,sina,len)b1 = A*cosa^2 + 12*I*sina^2/len^2;b2 = A*sina^2 + 12*I*cosa^2/len^2;b3 = (A-12*I/len^2)*cosa*sina;b4 = 6*I*sina/len;b5 = 6*I*cosa/len;y = E / len * [...	+b1,+b3,-b4,-b1,-b3,-b4;...	+b3,+b2,+b5,-b3,-b2,+b5;...	-b4,+b5,4*I,+b4,-b5,2*I;...	-b1,-b3,+b4,+b1,+b3,+b4;...	-b3,-b2,-b5,+b3,+b2,-b5;...	-b4,+b5,2*I,+b4,-b5,4*I];end``
``>> fun_BeamFrameStiff2D(1,1,1,1,1,1)ans =    13   -11    -6   -13    11    -6   -11    13     6    11   -13     6    -6     6     4     6    -6     2   -13    11     6    13   -11     6    11   -13    -6   -11    13    -6    -6     6     2     6    -6     4>> ``