Help storing for loop iterations

6 views (last 30 days)
bp
bp on 28 Oct 2016
Answered: LauraLee Austin on 28 Oct 2016
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.

Answers (1)

LauraLee Austin
LauraLee Austin on 28 Oct 2016
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.

Categories

Find more on Loops and Conditional Statements 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!