simplifying kinda-eye matrix of NxN, how?

1 回表示 (過去 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 Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by