필터 지우기
필터 지우기

How to generate a random matrix ?

조회 수: 389 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 17일
이동: Image Analyst 2022년 11월 1일
how to generate (4,4) a 20 binary random matrix in one function? like this
x1 = [ 1 0 1 0
1 1 0 0
0 1 1 0
0 0 1 0 ]
x2 = [ 1 1 0 1
0 1 0 0
1 1 0 1
0 1 0 1 ]
.
.
.
.
x20 = [ 1 0 1 0
0 0 0 1
1 1 1 0
1 0 1 1 ]

답변 (3개)

Image Analyst
Image Analyst 2016년 4월 17일
편집: Image Analyst 2016년 4월 17일
Try this:
x1 = randi([0, 1], [4,4])
Repeat for all of the other x. Or else (better because it's possibly more convenient), make a 3D array of 4-by-4-by-20.
Note: x1 is a double. If you want a binary as a boolean or logical, cast to logical:
x1 = logical(randi([0, 1], [4,4]))
  댓글 수: 3
Hirak Basumatary
Hirak Basumatary 2019년 6월 14일
How to generate unique random matrices ? Any algo for this?
Image Analyst
Image Analyst 2019년 6월 14일
You can use isequal() to compare the new matrix against any prior matrix.
if ~isequal(testMatrix, existingMatrix)
% Generate new test matrix
end

댓글을 달려면 로그인하십시오.


Harshit Agarwal
Harshit Agarwal 2019년 4월 1일
theta = [2,1]
  댓글 수: 1
Image Analyst
Image Analyst 2019년 4월 1일
That is not a 4-by-4 square. And, it is not binary. So it's not an answer to Firas's question.

댓글을 달려면 로그인하십시오.


Jenin
Jenin 2022년 10월 31일
이동: Image Analyst 2022년 11월 1일
You can use x = rand(4,4,20), It will gives you 20 set of 4x4 matrices.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by