For loop and matrices w/ different elements?

I have the followling code which has values calculated that are inputs of two matrices A and B. The inputs are values that are calculated in a for loop of i=1:365 corresponding to 1 degree to 360 degrees. I need each value computed by dividing the matrices at each degree/iteration. Everything else works besides the matrix part. I am not including the portions of my code that calculate the inputs but know they are within the for loop
for i=1:360
%All my stuff getting the inputs of the matrices
A(i)=[1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0
-R12x(i) R12y(i) -R32y(i) R32x(i) 0 0 0 1
0 0 -1 0 1 0 0 0
0 0 0 -1 0 1 0 0
0 0 R23y(i) -R23x(i) -R43y(i) R43x(i) 0 0
0 0 0 0 -1 0 0 0
0 0 0 0 0 -1 1 0]
B(i)=[m2.*A2x(i)
m2.*A2y(i)
I2*a2
m3*A3x(i)
m3*A3y(i)
I3*a3(i)
m4*A4x(i)-F4x(i)
0];
F(i)=A(i).\B(i)
end

1 件のコメント

Buster
Buster 2021 年 10 月 27 日
i get the error -"Unable to perform assignment because the left and right sides have a different number of elements"

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

 採用された回答

David Hill
David Hill 2021 年 10 月 27 日

0 投票

B(i)=[m2.*A2x(i);
m2.*A2y(i);
I2*a2;
m3*A3x(i);
m3*A3y(i);
I3*a3(i);
m4*A4x(i)-F4x(i);
0];%need 8x1 matrix

5 件のコメント

Buster
Buster 2021 年 10 月 27 日
The equation is A*F=B where F is [8x1] and A=[8x8]. Im solving for F so could you elaborate on your answer a little bit? I apologize.
David Hill
David Hill 2021 年 10 月 27 日
B(i) needs to be a 8x1. If you do not put semicolons in or transpose, the way you have B(i) currently written is a 1x8 array.
Buster
Buster 2021 年 10 月 27 日
I did as you presented yet im still getting the error
"Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
Error (line 52)
A(i)=[1 0 1 0 0 0 0 0
David Hill
David Hill 2021 年 10 月 27 日
Sorry, need to understand your variables. If you need to store all A matrices, you will need to make a 3-dimensional matrix.
A(:,:,i)=[1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0
-R12x(i) R12y(i) -R32y(i) R32x(i) 0 0 0 1
0 0 -1 0 1 0 0 0
0 0 0 -1 0 1 0 0
0 0 R23y(i) -R23x(i) -R43y(i) R43x(i) 0 0
0 0 0 0 -1 0 0 0
0 0 0 0 0 -1 1 0];
B(:,i)=[m2.*A2x(i);m2.*A2y(i);I2*a2;m3*A3x(i);m3*A3y(i);I3*a3(i);m4*A4x(i)-F4x(i);0];
F(:,i)=A(:,:,i)\B(:,i);
Buster
Buster 2021 年 10 月 27 日
Thank you so much

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2019a

質問済み:

2021 年 10 月 27 日

コメント済み:

2021 年 10 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by