How do I store matrix solutions from a loop into another matrix?

How do I populate the T matrix with Tr matrices for each n=1:6, so that I can access the elements with T(3:3;3:3,2)?
T=zeros(6,1);
for n= 1:6
Tr = [c(n) -s(n)*ca(n) s(n)*sa(n) a(n)*c(n);...
s(n) c(n)*ca(n) -c(n)*sa(n) a(n)*s(n);...
0 sa(n) ca(n) d(n);...
0 0 0 1 ] ;
T(:,:,n)=Tr;

 採用された回答

dpb
dpb 2015 年 12 月 1 日

0 投票

T has to be size of Tr in each plane; not sure where you got the 6,1 from...
T=zeros(4,4,6);
for n=1:6
T(:,:,n)=[c(n) -s(n)*ca(n) s(n)*sa(n) a(n)*c(n);...
s(n) c(n)*ca(n) -c(n)*sa(n) a(n)*s(n);...
0 sa(n) ca(n) d(n); ...
0 0 0 1 ];

2 件のコメント

Lorenzo
Lorenzo 2015 年 12 月 1 日
great, it works. I was thinking as T as a 6x1 array with matrix elements in it, rather than a 3D matrix.
Thanks!
dpb
dpb 2015 年 12 月 1 日
"T as a 6x1 array with matri[ces] in it..."
That would be a cell array, then...
T{n,1}=RHS;
instead. See
doc cell % and background info on cell arrays for details

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2015 年 11 月 30 日

コメント済み:

dpb
2015 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by