Info
This question is closed. Reopen it to edit or answer.
if r=rand(2,8) . I wanna find every element which is smaller than 0.5 and replace it with any other number say 0 or 1 or 2. how to do it....??
1 view (last 30 days)
Show older comments
if r=rand(2,8) . I wanna find every element in r which is smaller than 0.5 and replace it with any other number; say 0 or 1 or 2. how to do it....??
1 Comment
Answers (1)
Azzi Abdelmalek
on 9 Nov 2013
r(r<0.5)=0
3 Comments
Azzi Abdelmalek
on 9 Nov 2013
Edited: Azzi Abdelmalek
on 9 Nov 2013
If you want, but it's unnecessary
r=rand(2,8)
idx=find(r<0.5)
r(idx)=0
Michael
on 9 Nov 2013
IF you need you could find even more particular values using logical AND & (here && since scalar) or logical OR |
r(0.3<r && r<0.5) = 59
r(0.2>r || r>0.99) = 13
such as the above. Good Luck.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!