how to create random value matrix with size 3X5?

조회 수: 48 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by