How to store n iterations of randomly generated matrices

1 visualización (últimos 30 días)
N/A
N/A el 29 de Jul. de 2022
Respondida: Torsten el 29 de Jul. de 2022
To whom may be able to provide help,
Below is an algorithm that computes randomly generated matrices (of size 3x3). The values of the main diagonal are generated randomly, while the non-diagonal values are zero (as intentionally set). My goal is to store n randomly generated matrices in an array so that I may later plot them . How can I achieve this? The code as I have set-up gives me all zero matrices except the last iteration.
n = 10 ;
bounds = [1 100] ; %interval over which the random number generator will produce values
for i = 1:n
randA = diag(diag(randi(bounds, 3,3)))
randA_all(:,:,n) = randA
end

Respuestas (1)

Torsten
Torsten el 29 de Jul. de 2022
n = 10 ;
bounds = [1 100] ; %interval over which the random number generator will produce values
randA = zeros(3,3);
randA_all = zeros(3,3,n);
for i = 1:n
randA = diag(diag(randi(bounds, 3,3)));
randA_all(:,:,i) = randA;
end

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by