Help storing for loop iterations

조회 수: 2(최근 30일)
bp 2016년 10월 28일
답변: LauraLee Austin 2016년 10월 28일
I am having trouble trying to calculate the stresses for each layer in a composite laminate, where the program prompts the user to input the number of layers, fiber orientation per layer and material properties, etc. The relevant parts of the code are as follows:
%prompts user for fiber angles and then stores values into a matrix.
i=0;
theta=zeros(nlayers,1);
while i<nlayers
fprintf('\n Layer %d:',i+1);
prompt=' The fiber angle of the ply is ';
ang=input(prompt)
i=i+1;
theta(i,1)=theta(i,1)+ang;
end
%Qbar is a function with inputs Q and theta. Outputs a 3x3 stiffness matrix for each layer. (#layers=#matrices needed)
for i=1:nlayers
Q_bar=Qbar(Q,theta(i))
i=i+1;
end
Later on, the 3x1 strain matrix for each layer is calculated using another function.
for i=1:nlayers
strain = Strains(eps_xo,eps_yo,gam_xyo,kap_xo,kap_yo,kap_xyo,z(i))
i=i+1
end
It works fine up until I try calculate the 3x1 stress matrix for each layer where Stress=Q_bar*strain. I tried using another for loop but I keep getting an error message stating "Subscripted assignment dimension mismatch." I'm fairly new to using matlab and am not really sure how to proceed.

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

답변(1개)

LauraLee Austin 2016년 10월 28일
You do not need to increment i in the for loops, it's incremented automatically.
Q_bar is 3x3 and strain 3x1, this is the dimension mismatch.

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

범주

Find more on Stress and Strain in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by