Replacing min and max values
3 views (last 30 days)
Show older comments
For a given matrix I need to replace each element which is not min or max with the value 99
For example let
M=[5 0 2;8 3 1;1 8 0]
I tried the following code
M(M~=min(M(:))|M~=max(M(:)))=99;
but it replace all the matrix elements include 8 and 0 which are the max/min elements
0 Comments
Answers (1)
Star Strider
on 25 Mar 2018
Use ‘logical indexing’:
M=[5 0 2;8 3 1;1 8 0];
Mn = M == min(M)
Mx = M == max(M)
I leave the rest to you.
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!