help on error message

13 次查看(过去 30 天)
am getting error that says
Error using horzcat
Dimensions of arrays being concatenated are not
consistent.
Error in Plot2DBarBeam (line 364)
disp([(1:EL)' out.M1/1E3]);
Error in A1_general (line 38)
Plot2DBarBeam(inp,out,plt,file);
the code reffered as wrong is as far as i understand is :
% Axial forces
Nx = @(EA,L,u1,u2) (EA/L)*(u2-u1); % function for the axial force
Mz= @ (E,I,Le,x,v1,d1,v2,d2) E*I*((-6/Le^2+12*x/Le^3)*v1+(-4/Le+6*x/Le^2)...
*d1+(6/Le^2-12*x/Le^3)*v2+(-2/Le+6*x/Le^2)*d2);
for i=1:EL
% transformation matrix
d_prim = T*D(edof(i,:)); % local displacements, EL_i
N(i) = Nx(E*A,Le(i),d_prim(1),d_prim(4));
M1(i)=Mz(E,I,Le(i),0,d_prim(2),d_prim(3),d_prim(5),d_prim(6));
M2(i)=Mz(E,I,Le(i),Le(i),d_prim(2),d_prim(3),d_prim(5),d_prim(6));
V(i)=E*I*((12/Le(i)^3)*d_prim(2)+(6/Le(i)^2)*d_prim(3)+(-12/Le(i)^3)*d_prim(5)+(6/Le(i)^2)*d_prim(6)) ;
I can not understand what the error implies, would like to have some hints to solve this error?
Thanks,

采纳的回答

Geoff Hayes
Geoff Hayes 2020-4-17
Daniel - in the line of code
disp([(1:EL)' out.M1/1E3]);
you are horizontally concatenating the column (because of the transpose) array (1:EL)' with whatever out.M1/1E3 is. If both of these parameters don't have the same number of rows, then you will observe this error. What are the dimensions of the second parameter?
  2 个评论
Daniel Mehari
Daniel Mehari 2020-4-17
What I want to do is lets say i have EL elements
EL=number of elements
I wanted to calculate Moments that is M1,M2 and shear V
so for each bar I have EL number of M1,M2,V
the dimension will be like EL rows and 1 column.
Thnks for your swift reply
Daniel Mehari
Daniel Mehari 2020-4-17
I have understood now. Thanks.

请先登录,再进行评论。

更多回答(2 个)

Image Analyst
Image Analyst 2020-4-17
See if this explains it:
% Define 1-D row vectors and 2-D matrix.
v1 = [1,2,3] % One row vector.
v2 = [4,5,6] % Another one-row vector.
m = [1,2,3; 7,8,9] % A two-row matrix.
% Now try to horizontally concatenate them.
% These lines will work:
v12a = horzcat(v1, v2) % This will work because both have one row.
v12b = [v1, v2] % This will work because both have one row.
% Neither of these will work because you can't have different number of rows in each column.
% In other words you can't have
% 1 2 3 1 2 3
% 7 8 9
% Because columns 1-3 have only 1 row while columns 4-6 would have two rows.
badMatrix = horzcat(v1, m) % Throws error
badMatrix = [v1, m] % Throws error
% Running either of those two lines would throw this error:
% Error using horzcat
% Dimensions of arrays being concatenated are not consistent.
You'll see
v1 =
1 2 3
v2 =
4 5 6
m =
1 2 3
7 8 9
v12a =
1 2 3 4 5 6
v12b =
1 2 3 4 5 6
Then, at the next line, when you try to horizontally concatenate a matrix onto a row vector, you'll see:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.

Daniel Mehari
Daniel Mehari 2020-4-18
Many Thanks

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by