how to apply relational operators on matrix elements?
3 次查看(过去 30 天)
显示 更早的评论
i=[1 2 3 -4;5 -7 8 9;5 6 7 -7;3 4 -2 4]; i want to replace the elements of above matrix with the value greater than 4 by 4, and the matrix elements less than -4 by -4.
0 个评论
采纳的回答
James Tursa
2013-1-11
编辑:James Tursa
2013-1-11
i(i>4) = 4;
i(i<-4) = -4;
or
i = min(max(i,-4),4);
But in the future avoid i as a variable name since that is what MATLAB uses for the imaginary number sqrt(-1).
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!