Can someone help me write a code to generate a random matrix like the one in the picture?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Réponse acceptée
Ameer Hamza
le 25 Sep 2020
Modifié(e) : Ameer Hamza
le 25 Sep 2020
See blkdiag(): https://www.mathworks.com/help/matlab/ref/blkdiag.html. It is made specifically for this purpose. For example
d = 3;
N = 3;
C = cell(N, 1);
for i=1:N
C{i} = rand(d);
end
M = blkdiag(C{:});
Result
>> M
M =
0.9106 0.1455 0.5797 0 0 0 0 0 0
0.1818 0.1361 0.5499 0 0 0 0 0 0
0.2638 0.8693 0.1450 0 0 0 0 0 0
0 0 0 0.8530 0.5132 0.2399 0 0 0
0 0 0 0.6221 0.4018 0.1233 0 0 0
0 0 0 0.3510 0.0760 0.1839 0 0 0
0 0 0 0 0 0 0.2400 0.9027 0.4893
0 0 0 0 0 0 0.4173 0.9448 0.3377
0 0 0 0 0 0 0.0497 0.4909 0.9001
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!