MATLAB Answers

Matrix with for cycle

4 ビュー (過去 30 日間)
Carlos Betancur
Carlos Betancur 2020 年 10 月 6 日
コメント済み: Carlos Betancur 2020 年 10 月 6 日
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)

  0 件のコメント

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2020 年 10 月 6 日
Qbar = cell(N, 1); % preallocate properly for other variables also
Qbar{ii} = ... inside loop

  5 件のコメント

表示 2 件の古いコメント
Carlos Betancur
Carlos Betancur 2020 年 10 月 6 日
I get an error when entering the last value of ii, so it does not create the last matrix Qbar{ii}.
error: Codigo_V5: Invalid resizing operation or ambiguous assignment to an out-of-bounds array ele
ment
thanks
madhan ravi
madhan ravi 2020 年 10 月 6 日
If you copied my code correctly, it’s highly unlikely to get that error message.
Carlos Betancur
Carlos Betancur 2020 年 10 月 6 日
Thanks !

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by