I want to build a matrix with random elements, but the number of elements in each row equals one. Please help with the syntax.

댓글 수: 2

Fangjun Jiang
Fangjun Jiang 2024년 3월 18일
@susila bahri, Is it the number of non-zero element in each row is one, or the sum of each row equals one?

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2024년 3월 18일
편집: Voss 2024년 3월 18일

0 개 추천

% number of rows:
N = 8;
Here are some example random matrices where each row has one element, which is what you asked for:
rand(N,1) % elements drawn from the uniform distribution between 0 and 1
ans = 8×1
0.3365 0.3005 0.4159 0.8534 0.9443 0.4622 0.8110 0.9743
randn(N,1) % elements drawn from the standard normal distribution
ans = 8×1
-0.3203 -1.8483 0.7423 -1.0262 0.6144 0.9617 -1.0404 -1.1750
randi([6,9],N,1) % uniformly distributed integers between 6 and 9
ans = 8×1
8 9 8 9 7 9 7 8

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2024년 1월 22일

편집:

2024년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by