how to create random value matrix with size 3X5?

33 visualizzazioni (ultimi 30 giorni)
SEID
SEID il 18 Giu 2022
Risposto: DGM il 18 Giu 2022
my question is to create 3x5 matrix add its elemet is radomly from 1-10.

Risposte (2)

Ayush Singh
Ayush Singh il 18 Giu 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 il 18 Giu 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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by