From: mins alaa on
I would like to generate a 15 * 20 random matrix ranging from -2 and 2, and then find the maximum and minimum values inside the matrix. Then using loops, set all matrix elements that exceed the value of 1.2 to the maximum while setting the elements below -1.2 to the minimum. Can someone help me please?
From: Ulf Graewe on
"mins alaa" <zabola10(a)yahoo.com> wrote in message <hputqv$h6n$1(a)fred.mathworks.com>...
> I would like to generate a 15 * 20 random matrix ranging from -2 and 2, and then find the maximum and minimum values inside the matrix. Then using loops, set all matrix elements that exceed the value of 1.2 to the maximum while setting the elements below -1.2 to the minimum. Can someone help me please?

What have you done unitl now?
Can you show a piece of code, and where you are stuck?

In the worst case, the MATLAB documentation is always your friend!

doc rand
doc min
doc max
doc find
From: Luca Balbi on
And unless you're forced to, don't use loops!

mtx = 4*(rand(15,20)-0.5);
valueMin = min(mtx(:));
valueMax = min(mtx(:));
mtx(mtx<-1.2) = valueMin;
mtx(mtx>1.2) = valueMax;