Matrix with for cycle

3 views (last 30 days)
Carlos Betancur
Carlos Betancur on 6 Oct 2020
Commented: Carlos Betancur on 6 Oct 2020
Hello I want to create an i number of matrix with the arrangement that Qbar shows, but it generates a dimension error, what can I do?
for i=1:N
a(i) = input('Direction [deg]: ');
theta_deg = a(i);
theta_rad = theta_deg*pi/180;
Qbar_11(i) = Q_11*((cos(theta_rad))^4)+2*(Q_12+2*Q_66)*((sin(theta_rad))^2)*((cos(theta_rad))^2)+Q_22*((sin(theta_rad))^4);
Qbar_12(i) = (Q_11+Q_22-4*Q_66)*((sin(theta_rad))^2)*((cos(theta_rad))^2)+Q_12*(((sin(theta_rad))^4)+((cos(theta_rad))^4));
Qbar_22(i)= Q_11*((sin(theta_rad))^4)+2*(Q_12+2*Q_66)*((sin(theta_rad))^2)*((cos(theta_rad))^2)+Q_22*((cos(theta_rad))^4);
Qbar_16(i) = (Q_11-Q_12-2*Q_66)*(sin(theta_rad))*((cos(theta_rad))^3)+(Q_12-Q_22+2*Q_66)*((sin(theta_rad))^3)*(cos(theta_rad));
Qbar_26(i) = (Q_11-Q_12-2*Q_66)*((sin(theta_rad))^3)*(cos(theta_rad))+(Q_12-Q_22+2*Q_66)*(sin(theta_rad))*((cos(theta_rad))^3);
Qbar_66(i) = (Q_11+Q_22-2*Q_12-2*Q_66)*((sin(theta_rad))^2)*((cos(theta_rad))^2)+Q_66*(((sin(theta_rad))^4)+((cos(theta_rad))^4));
Qbar(i) = [Qbar_11(i),Qbar_12(i),Qbar_16(i);Qbar_12(i),Qbar_22(i),Qbar_26(i);Qbar_16(i),Qbar_26(i),Qbar_66(i)]
end
the error is ꃭ؀error: Codigo_V4: =: nonconformant arguments (op1 is 1x1, op2 is 3x3)

Accepted Answer

madhan ravi
madhan ravi on 6 Oct 2020
Qbar = cell(N, 1); % preallocate properly for other variables also
Qbar{ii} = ... inside loop
  5 Comments

Sign in to comment.

More Answers (0)

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!

Translated by