How can I add random noise using the rand function with the noise being uniformly distributed between 0 and 2?

If I have a new vector z=a1x^2 - a2y^2 + a3xy, how can I add random noise to all the elements in z using the function rand()? The noise needs to be uniformly distributed between 0 and 2.

回答 (1 件)

Amit
Amit 2014 年 1 月 27 日
z=a1*x.^2 - a2*y.^2 + a3*x.*y + 2*rand(size(x));

5 件のコメント

Adrian
Adrian 2014 年 1 月 27 日
Thank you so much. If I had already defined the vector before as z=a1*x.^2 - a2*y.^2 + a3*x.*y Can I just write: z = z + 2*rand(size(x)); ?
Amit
Amit 2014 年 1 月 27 日
That would work.
Adrian
Adrian 2014 年 1 月 28 日
Thank you. I just had one more question. If I need to use the nlinfit() function to find the coefficients 1,2,3 so that so that the surface of z is the best fit to the noisy data, do you know how I could do that?
Amit
Amit 2014 年 1 月 28 日
Didn't you already answered that? nlinfit()
For documentation regarding nlinfit: http://www.mathworks.com/help/stats/nlinfit.html
Adrian
Adrian 2014 年 1 月 28 日
Ok, thank you.

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2014 年 1 月 27 日

コメント済み:

2014 年 1 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by