How can assign numbers between two integer numbers instead of ones in a [0 1] matrix?

1 回表示 (過去 30 日間)
Abdullah Türk
Abdullah Türk 2023 年 6 月 11 日
コメント済み: Matt J 2023 年 6 月 11 日
Hi everyone,
I formed following matrice using randi([0,1],6,5).
1 0 1 0 0
1 0 1 0 0
1 0 0 0 1
0 1 0 0 1
1 1 1 0 1
1 1 0 1 0
In this matrice, I want to assign random numbers that between two integer nembers instead of just ones. This is possible? Thanks.

回答 (1 件)

Matt J
Matt J 2023 年 6 月 11 日
編集済み: Matt J 2023 年 6 月 11 日
Sure.
randi([lower,upper], 6,5)
  2 件のコメント
Abdullah Türk
Abdullah Türk 2023 年 6 月 11 日
Matt thanks but I want assign random numbers to ones in the matrice. I firstly create [0 1] matrice and then in this matrice, I want to assign random numbers that between two integer numbers to ones.
Matt J
Matt J 2023 年 6 月 11 日
lower=3;
upper=7;
randi([0,1], 6,5).*randi([lower,upper],6,5)
ans = 6×5
0 0 0 0 7 4 0 0 4 4 0 0 0 6 4 0 6 0 0 4 0 0 3 0 0 0 0 7 7 3

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by