필터 지우기
필터 지우기

simplifying kinda-eye matrix of NxN, how?

조회 수: 2 (최근 30일)
M Adli Hawariyan
M Adli Hawariyan 2022년 7월 10일
댓글: M Adli Hawariyan 2022년 7월 10일
greetings, here's the problem:
i have a matrix like this:
A = [cosx_X cosx_Y cosx_Z
cosy_X cosy_Y cosy_Z
cosz_X cosz_Y cosz_Z]
cosx_X = alp(d,1);cosx_Y = alp(d,2);cosx_Z = alp(d,3);
cosy_X = alp(d,4);cosy_Y = alp(d,5);cosy_Z = alp(d,6);
cosz_X = alp(d,7);cosz_Y = alp(d,8);cosz_Z = alp(d,9);
t = [cosx_X cosx_Y cosx_Z 0 0 0 0 0 0 0 0 0;
cosy_X cosy_Y cosy_Z 0 0 0 0 0 0 0 0 0;
cosz_X cosz_Y cosz_Z 0 0 0 0 0 0 0 0 0;
0 0 0 cosx_X cosx_Y cosx_Z 0 0 0 0 0 0;
0 0 0 cosy_X cosy_Y cosy_Z 0 0 0 0 0 0;
0 0 0 cosz_X cosz_Y cosz_Z 0 0 0 0 0 0;
0 0 0 0 0 0 cosx_X cosx_Y cosx_Z 0 0 0;
0 0 0 0 0 0 cosy_X cosy_Y cosy_Z 0 0 0;
0 0 0 0 0 0 cosz_X cosz_Y cosz_Z 0 0 0;
0 0 0 0 0 0 0 0 0 cosx_X cosx_Y cosx_Z;
0 0 0 0 0 0 0 0 0 cosy_X cosy_Y cosy_Z;
0 0 0 0 0 0 0 0 0 cosz_X cosz_Y cosz_Z ];
any tips for simplify the writing of matrix? any guidance will help me alot, thanks

채택된 답변

KSSV
KSSV 2022년 7월 10일
A = rand(3) ;
[m,n] = size(A) ;
iwant = zeros(4*m,4*n) ;
for i = 1:4
idx = (1:m)+(i-1)*3 ;
iwant(idx,idx)=A;
end
spy(iwant)

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 7월 10일
To build A from alp use reshape and transpose.
To build t from A use blkdiag.
  댓글 수: 1
M Adli Hawariyan
M Adli Hawariyan 2022년 7월 10일
Hello admin, i want to ask about blkdiag.
my data ALP is from loop data;
ALP = [cosx_X cosx_Y cosx_Z
cosy_X cosy_Y cosy_Z
cosz_X cosz_Y cosz_Z]
if i want to make the desired t (like answer above), how to make ALP in t is still continue? i got the answer like this; t1 is good answer, but t2 is not
for d=1:3
alp = [ 1 0 0 0 1 0 0 0 1;
1 0 0 0 1 0 0 0 1;
1 0 0 0 1 0 0 0 1]
%angle for t matrix placing
ALP = (reshape(alp(d,1:9),[3,3]))'
[m,n] = size(ALP);
t1 = zeros(4*m,4*n);
for ii = 1:4
idx = (1:m)+(ii-1)*3;
t1(idx,idx)=ALP;
end
tt = transpose(t);
t2 = blkdiag(ALP)
end
t2 answer when loop d=1:2
ALP =
1 0 0
0 1 0
0 0 1
t2 =
1
ALP =
1 0 0
0 1 0
0 0 1
t2 =
0
any suggestions? thanks alott

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

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by