help on error message

11 views (last 30 days)
Daniel Mehari
Daniel Mehari on 17 Apr 2020
Answered: Daniel Mehari on 18 Apr 2020
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,

Accepted Answer

Geoff Hayes
Geoff Hayes on 17 Apr 2020
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 Comments
Daniel Mehari
Daniel Mehari on 17 Apr 2020
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 on 17 Apr 2020
I have understood now. Thanks.

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 17 Apr 2020
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 on 18 Apr 2020
Many Thanks

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!