How to reassign matrix if it is greater than some value quickly

조회 수: 4 (최근 30일)
John Wray
John Wray 2016년 4월 19일
편집: per isakson 2016년 5월 17일
Considering a Matrix
a = [ 11 20 51 23 100 3
2 25 15 12 80 8
1 15 20 50 22 8
6 1 23 12 50 6 ]
Is there any function that could quickly reassign matrix to specific value if it is less than a value? such as b=10, if it is less than b, reassign it to 0, and having the answer like this:
ans = [ 11 20 51 23 100 0
0 25 15 12 80 0
0 15 20 50 22 0
0 0 23 12 50 0 ]

채택된 답변

Roger Stafford
Roger Stafford 2016년 4월 19일
M = a;
M(M<b) = 0;
M is your answer.

추가 답변 (1개)

Jan
Jan 2016년 4월 19일
Or:
b = a .* (a >= 10);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by