Generate matrices with non-zero submatrices

4 vues (au cours des 30 derniers jours)
Marsge
Marsge le 4 Juil 2017
Commenté : Marsge le 4 Juil 2017
Hi,
I would like to generate matrices with non-zero submatrices, which have form like
A1 = [1 1 0 ... 0 0
1 1 0 ... 0 0
0 0 0 ... 0 0
...
0 0 0 ... 0 0
0 0 0 ... 0 0]
A2 = [0 0 0 ... 0 0
0 1 1 ... 0 0
0 1 1 ... 0 0
...
0 0 0 ... 0 0
0 0 0 ... 0 0]
...
and
An = [0 0 0 ... 0 0
0 0 0 ... 0 0
0 0 0 ... 0 0
...
0 0 0 ... 1 1
0 0 0 ... 1 1]
How can I generate the matrix Ak by MATLAB command?

Réponse acceptée

Guillaume
Guillaume le 4 Juil 2017
n = 10; %for example
A = arrayfun(@(k) blkdiag(zeros(k-1), ones(2), zeros(n-k)), 1:n, 'UniformOutput', false);
celldisp(A)
A{k} is the kth matrix.
  1 commentaire
Marsge
Marsge le 4 Juil 2017
Thank @Guillaume very much! That's the stuff I need.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by