a=rand(400), this function generates 400*400 random matrix a,how could generate matrix a with specified mean and variance.

a=rand(400), this function generates 400*400 random matrix a,how could generate matrix a with specified mean and variance in matlab.

댓글 수: 3

what do you mean? and what you feel
If a poster honestly admits it's homework, then we will give hints rather than full solutions so they can't be accused of plagiarizing, and won't feel guilty about turning in someone else's code as their own. It appears that you imply this is not your homework, so don't worry about it.

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 12월 24일
편집: Andrei Bobrov 2012년 12월 24일
m - your mean
s - your variance
size_matrix - size of your array < a x b > , size_matrix = [a,b];
fun1 = @(m,s,size_matrix) m + sqrt(s)*randn(size_matrix)
use function fun1, eg:
>> fun1(1,2,[3,2])
please read about randn
if you have Statistics Toolbox, use function normrnd:
>> normrnd(m,sqrt(s),size_matrix);

댓글 수: 6

fun1 = 20 + sqrt(0.6)*randn(400); here i got mean=19.9995 it is ok but i don'i get variance ok. i got it 0.0018
fun1 = 20 + sqrt(0.6)*randn(400) why this function does not give right answer?
fun1= normrnd(20,sqrt(0.6),[400 400]);
fun1 = 20 + sqrt(0.6)*randn(400);
both function gives proper mean but it does not give proper variance
i.e nearest 0.6
Why use randn() or normrnd()? vipul, in your original post you hinted at a uniform distribution because you used rand(). The suggestion to look at normal distributions is good though. But which distribution do you want? It seems strange that you would switch from one to another since they are so different. Have you given the shape of the distribution any thought?
this is different question compared to you answered (homogeneous area...)
and i got solution
Yes I know I answered a different question from you in a different discussion but the comment I made here was related to this discussion. Usually people care about what shape their noise distribution takes and I was just wondering why you don't, because it has a huge impact on the results. But whatever, as long as you think you have a solution....

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

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

질문:

2012년 12월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by