Generating a random matrix which has zero entries as well

조회 수: 3 (최근 30일)
Mojtaba Mohareri
Mojtaba Mohareri 2021년 6월 5일
댓글: Mojtaba Mohareri 2021년 6월 5일
When I generate a random matrix (for example, with the following code)
bounds = [-15,10];
A = rand(m,m) * range(bounds) + bounds(1)
there is no zero entry in the matrix. Could you please tell me how can I create a random matrix which has zero entries as well?
  댓글 수: 7
the cyclist
the cyclist 2021년 6월 5일
There are several things you could do, but it depends on what properties you need your random distribution to have.
For example, you could generate the m*m random numbers as you originally did, but then generate a random number of zeros from 0:m*m, and fill them into random location in your array.
So, first, think carefully about what specific properties you need your random distribution to have, then we may be able to help you generate that distribution. It is not enough to say "numbers between -15 and 15, where some are zeros". You need to be very specific.
Mojtaba Mohareri
Mojtaba Mohareri 2021년 6월 5일
You are right. I sure will. Thank you very much for your exact eplanation.

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

답변 (0개)

카테고리

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