フィルターのクリア

Matrix Manipulations - How to achieve these specific forms?

1 回表示 (過去 30 日間)
Mathias Dirksmeier
Mathias Dirksmeier 2018 年 9 月 20 日
コメント済み: Mathias Dirksmeier 2018 年 9 月 20 日
Dear Community,
I am struggling to achieve two distinct forms of matrices.
1) I want to build a matrix with the following form and dimensions of [8760 x 2*8760]
(1 1 0 0 0 0 ...
0 0 1 1 0 0 ...
0 0 0 0 1 1 ...
...)
2) I want to build a matrix with the following form and dimensions of [2*8760 x 2*8760]
(0 0 0 0 0 0 ...
5 8 0 0 0 0 ...
0 0 0 0 0 0 ...
5 8 5 8 0 0 ...
...)
I just can't make that work, also I am fairly new to Matlab. I really hope somebody can see a solution here.
Thanks a lot, Mathias
  1 件のコメント
Stephen23
Stephen23 2018 年 9 月 20 日
Note: see Jos's answer if you actually want those matrices.

サインインしてコメントする。

採用された回答

Jos (10584)
Jos (10584) 2018 年 9 月 20 日
Bruno's and KSSV's answers do not create the matrices you asked for, or am I mistaken? Anyways, here are my suggestions:
N = 4 ; % small example, rather than N=8760
M1 = kron(eye(N), [1 1])
% 1 1 0 0 0 0 ...
% 0 0 1 1 0 0 ...
% 0 0 0 0 1 1 ...
% ...
M2 = kron(tril(ones(N)), [0 0 ; 5 8])
% 0 0 0 0 0 ...
% 5 8 0 0 0 ...
% 0 0 0 0 0 ...
% 5 8 5 8 0 ...
% ...
  2 件のコメント
Stephen23
Stephen23 2018 年 9 月 20 日
+1 this actually gives the matrices shown in the question.
Bruno Luong
Bruno Luong 2018 年 9 月 20 日
I'm not 100% convinced since in the example of (2) given by OP we can't see a 2x2 block far below the diagonal, so there is still a confusion whereas the lower-diagonal or 2-diagonal by block is needed.
In anycase he/she gets the receipt to build the matrix.

サインインしてコメントする。

その他の回答 (2 件)

Bruno Luong
Bruno Luong 2018 年 9 月 20 日
>> A=diag(ones(1,5),0)+diag(ones(1,4),-1)
A =
1 0 0 0 0
1 1 0 0 0
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1
>> kron(A,[2 3; 5 8])
ans =
2 3 0 0 0 0 0 0 0 0
5 8 0 0 0 0 0 0 0 0
2 3 2 3 0 0 0 0 0 0
5 8 5 8 0 0 0 0 0 0
0 0 2 3 2 3 0 0 0 0
0 0 5 8 5 8 0 0 0 0
0 0 0 0 2 3 2 3 0 0
0 0 0 0 5 8 5 8 0 0
0 0 0 0 0 0 2 3 2 3
0 0 0 0 0 0 5 8 5 8
>>
  4 件のコメント
Bruno Luong
Bruno Luong 2018 年 9 月 20 日
編集済み: Bruno Luong 2018 年 9 月 20 日
The first question is easily extrapolated (I did not give the answer for the first question)
FirstQuestionMat =diag(ones(1,5),0)+diag(ones(1,4),+1)
If you claim my solution for the second quetion is good, then Jos's answer is not, and vice-versa.
Look again the results, and be clear in you mind.
Better learn the technique rather than take the answer as it is.
Mathias Dirksmeier
Mathias Dirksmeier 2018 年 9 月 20 日
Sorry, you are right. Your solution does not solve my problem.

サインインしてコメントする。


KSSV
KSSV 2018 年 9 月 20 日
Read about diag
N = 10 ;
A = diag(ones(N,1))+diag(ones(N-1,1),-1) ;

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by