simplifying kinda-eye matrix of NxN, how?

1 次查看(过去 30 天)
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