c=(exp((-z​^2)/(2*sig​ma^2)))+mn​oise

How do you add mnoise which is a 251 data with normal distribution and derivation 0.02. When I added mnoise It says there is an error with + matrices

 채택된 답변

Amit
Amit 2014년 2월 1일

0 개 추천

mnoise = 0.02*randn(251,1);

댓글 수: 5

Ajay  Joseph
Ajay Joseph 2014년 2월 1일
Sorry amit my questions was that I think I forgot to add the rest of the question c=(exp((-z^2)/(2*sigma^2)))+mnoise and when I add mnoise there is an error
Amit
Amit 2014년 2월 1일
that might have been that the dimension of first term and second term were different.
What was the error? Matlab generally tell the error. Can you post that.
Also, can you add an example for z, sigma and mnoise values.
Ajay  Joseph
Ajay Joseph 2014년 2월 1일
Error using + Matrix dimensions must agree. This was the error
The s value is just a linear number like 2.31 The z value is a matix z=linspace(-7,7,251) Mnoise is = 0.02*randn(251,1)
Here, the issue is
z = linspace(-7,7,251); % This is a row vector
mnoise = 0.02*randn(1,251); % Now we made this a row vector as well
This time this will work :)
Ajay  Joseph
Ajay Joseph 2014년 2월 1일
Damn thanks man The simplest things makes a big difference

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

추가 답변 (1개)

John D'Errico
John D'Errico 2014년 2월 1일

1 개 추천

It appears you have not realized there is a difference between row and column vectors. This is a common mistake, since a vector is just a vector, right? In fact, MATLAB sees a vector as just an array with the row or column dimension equal to 1. That makes a lot of sense in a linear algebra context, which is really where MATLAB comes from.
LINSPACE (like COLON) creates row vectors, so an array of size 1 by n.
A good way to add noise to an array or vector without bothering to know the size is...
y = y + randn(size(y)).*0.02;
RANDN by default generates Gaussian deviates with mean zero and standard deviation 1. Multiplying by 0.02 scales them to have standard deviation 0.02.

댓글 수: 1

Ajay  Joseph
Ajay Joseph 2014년 2월 1일
thanks but I guess Amit answer works aswell

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

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

질문:

2014년 2월 1일

댓글:

2014년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by