Filter löschen
Filter löschen

simplifying kinda-eye matrix of NxN, how?

2 Ansichten (letzte 30 Tage)
M Adli Hawariyan
M Adli Hawariyan am 10 Jul. 2022
Kommentiert: M Adli Hawariyan am 10 Jul. 2022
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

Akzeptierte Antwort

KSSV
KSSV am 10 Jul. 2022
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)

Weitere Antworten (1)

Steven Lord
Steven Lord am 10 Jul. 2022
To build A from alp use reshape and transpose.
To build t from A use blkdiag.
  1 Kommentar
M Adli Hawariyan
M Adli Hawariyan am 10 Jul. 2022
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Time Series Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by