how to create random value matrix with size 3X5?

36 vues (au cours des 30 derniers jours)
SEID
SEID le 18 Juin 2022
Réponse apportée : DGM le 18 Juin 2022
my question is to create 3x5 matrix add its elemet is radomly from 1-10.

Réponses (2)

Ayush Singh
Ayush Singh le 18 Juin 2022
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 le 18 Juin 2022
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

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by