필터 지우기
필터 지우기

Write a matlab code to generate a 1 X N matrix with values in the range of 1-100 according to a normal distribution with mean= 0 and variance=1

조회 수: 64 (최근 30일)
Can anyone help me with this please
  댓글 수: 1
the cyclist
the cyclist 2021년 9월 18일
The question is confusing to me, especially where you say "in the range of 1-100".
If you mean that the values should be from 1-100, then how can the mean value be equal to 0?
Or do you mean that the matrix should be length N, but only elements 1-100 should be filled in? If so, then @Ravi Narasimhan's idea of using randn to fill in the first 100 elements should be straightforward.

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

답변 (2개)

Ravi Narasimhan
Ravi Narasimhan 2021년 9월 18일
The documentation for the randn function may be of interest.

Walter Roberson
Walter Roberson 2021년 9월 18일
편집: Walter Roberson 2021년 9월 18일
You can create a normal distribution and then truncate it. The truncated distribution still has total probability 1, which is handled by multiplying the probability density function by enough that its integral totals 1.The modified probability density function no longer has 0 mean and 1 standard deviation, though.
You can see from the distribution that even though values from 1 to 100 are permitted, that statistically there is very little beyind 3.5
D = makedist('normal', 0, 1);
Td = truncate(D, 1, 100);
N = 10000;
r = random(Td, 1, N);
r(1:10)
ans = 1×10
1.4222 1.3387 1.9644 1.1506 1.5914 1.3055 2.1571 1.5775 1.0056 1.1884
actual_mean = mean(r)
actual_mean = 1.5260
actual_std = std(r)
actual_std = 0.4451
histogram(r)

카테고리

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