How to store n iterations of randomly generated matrices

2 次查看(过去 30 天)
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

回答(1 个)

Torsten
Torsten 2022-7-29
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

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by