how to create random value matrix with size 3X5?

22 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by