Generation of Random matrices in ascending order
8 views (last 30 days)
Hi to all the matlab users. I want to generate 5 matrices of 3X3. the initial matrix is having all zeros. then the next 5 matrices that are generated should have random elements between 0 to pi but in ascending order at their respective loctions. e.g i am giving example 1st element of 1st matrix 0 1st element of 2nd matrix 0.0034 1st element of 3rd matrix 0.0139 1st element of 4th matrix 0.9861 1st element of 5th matrix 1.2345 1st element of 6th matrix 2.8904
similarly for other element.... Note: the element at same location of matrices are ascending. I hope I am able to clarify the question.
Image Analyst on 22 Oct 2016
This will do it:
% Get all 5 matrices in one 3D array in sorted order.
m3d = sort(pi * rand(3,3,5), 3)
% Extract out 5 separate, individual matrices.
matrix1 = m3d(:, :, 1)
matrix2 = m3d(:, :, 2)
matrix3 = m3d(:, :, 3)
matrix4 = m3d(:, :, 4)
matrix5 = m3d(:, :, 5)