replace array value with if condition

Hello
hello, i have samply array,I would like to replace all numbers greater than 5 to be 5 and lower than 4 to be 2
in my experiment above its success if condition greater than 5. How about lower than 2 it is posible? , and the result i want A=[2 2 2 2 5 5 5 5 5]
A=[4 4 4 4 5 6 7 8 9 ]
max(A)
min(A)
if max(A)>=5
A(A>=5)=5
end
Thanks a lot

답변 (1개)

KSSV
KSSV 2021년 7월 22일

0 개 추천

Let A be your array.
A(A>=5) = 5 ;
A(A<4) = 2 ;

댓글 수: 3

syaika bayu
syaika bayu 2021년 7월 22일
its work.
so i dont need max(A) and min(A) to do it why ?
KSSV
KSSV 2021년 7월 22일
편집: KSSV 2021년 7월 22일
If you know the values, give the values, if values are not known, use max amd min.
syaika bayu
syaika bayu 2021년 7월 22일
okey i understand
thank you very much, kssv

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2021년 7월 22일

댓글:

2021년 7월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by