フィルターのクリア

how to create random value matrix with size 3X5?

22 ビュー (過去 30 日間)
SEID
SEID 2022 年 6 月 18 日
回答済み: DGM 2022 年 6 月 18 日
my question is to create 3x5 matrix add its elemet is radomly from 1-10.

回答 (2 件)

Ayush Singh
Ayush Singh 2022 年 6 月 18 日
Hi SEID
From my understanding of your question I assume you want to create 3*5 matrix of random numbers from 1-10
You can use the 'randi' function ( Uniformly distributed pseudorandom integers ) in folllowing way-
mat = randi(10,3,5) % 3,5 is the size of the matrix and 10 is the upper range for the matrix elements.
mat = 3×5
8 8 5 10 8 4 1 9 4 8 6 6 10 8 1

DGM
DGM 2022 年 6 月 18 日
If the numbers are supposed to be integers:
A = randi([1 10],3,5)
A = 3×5
9 4 6 9 10 5 6 1 6 6 2 5 4 10 9
otherwise, if the numbers can be any value in the specified interval:
A = rand(3,5)*9+1
A = 3×5
6.1228 3.6624 6.5019 7.3853 1.8787 5.0588 4.5854 1.7705 8.1341 8.7430 3.2489 8.8081 4.4995 4.7077 2.4313

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by