Getting an error "Matrix Dimension must agree" in matlab program. Help me.

for epsilon3=-1:1:1
N_dash(1)=-0.5+epsilon3;
N_dash(2)=-2*epsilon3;
N_dash(3)=0.5+epsilon3;
end
for i=-1:1:1
epsilon3=(i)
lx=(epsilon3-0.5)*x(1)-(2*epsilon3)*x(2)+(epsilon3+0.5)*x(3);
mx=(epsilon3-0.5)*y(1)-(2*epsilon3)*y(2)+(epsilon3+0.5)*y(3);
nx=(epsilon3-0.5)*z(1)-(2*epsilon3)*z(2)+(epsilon3+0.5)*z(3);
%%Jacobian Factor
s=sqrt(((lx)^2)+(((mx)^2)+(((nx)^2))));
end
%%Tangent vector (ey) about y dirsction ly=(x(5)-x(2)); my=(y(5)-y(2)); ny=(z(5)-z(2));
lve=sqrt(((ly)^2)+((my)^2)+((ny)^2)); %%vertical length of element ey = [ly; my; ny] / lve; for i=1:8 B_matrix(1,i)=1/s*repmat(N_dash, 3, 1) .* repelem(ey, 3, 1) %(ERROR HERE)
end
x,y,z are constant values like 0.2132,0.9876 etc.
Error using .*
Matrix dimensions must agree.
Error in practisee2 (line 309)
B_matrix(1,i)=1/s*repmat(N_dash, 3, 1) .* repelem(ey, 3, 1)

답변 (1개)

Haritha
Haritha 2018년 10월 23일

0 개 추천

Hi Try this B_matrix(1,i)=1/s.*repmat(N_dash, 3, 1) .* repelem(ey, 3, 1)

댓글 수: 5

@Haritha Sorry. Not working.
I am stuck in this for last 2 days. Someone please help me get out of it.
Before the line
B_matrix(1,i)=...
insert the lines
size(repmat(N_dash, 3, 1))
size(repelem(ey, 3, 1))
in your code and take a look at what MATLAB tells you in the output window.
If the sizes of the two arrays differ, MATLAB will complain about "Matrix dimensions must agree". Furthermore, since B_matrix(1,i) is a single scalar, the two sizes must be 1. Since this is not the case, you will get an error anyhow.
Best wishes
Torsten.
N_dash has size 3x3 and ey 9x1. What can i do to make their size the same??
If N_dash has size 3x3, then repmat(N_dash,3,1) will produce an error. If ey has size 9x1, then repelem(ey,3,1) has size 27x1. No chance for elementwise multiplication.
And note again that the right-hand side ... of an assignment of the form
B_matrix(1,i) = ...
must have size 1x1.
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2018년 10월 23일

댓글:

2018년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by