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

How do I populate the T array with Tr matrices for each n=1:6, so that I can access the elements simply with T(3:3,3:3,2) (rows 1-3 colums 1-3 of the second matrix in T)?
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;
end

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 30일

0 개 추천

You cannot have T(3:3;3:3,2) mean (rows 1-3 colums 1-3 of the second matrix in T)? You would use T(1:3, 1:3, 2) to mean that.

댓글 수: 2

yes, sorry that's what I meant. Any ideas how to do it?
Initialize with T = zeros(4,4,6);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 11월 30일

댓글:

2015년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by