Can someone help me write a code to generate a random matrix like the one in the picture?

1 visualización (últimos 30 días)

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 25 de Sept. de 2020
Editada: Ameer Hamza el 25 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by