This should be an easy one.
If I have an array with...
0.203 0.506 0.167 0.904 1.671 5.247 0.037 0.679
How do I amend the individual values within the array that are greater than 1 and set them to 1?
e.g.
0.203 0.506 0.167 0.904 1.000 1.000 0.037 0.679
Thanks!

 채택된 답변

ES
ES 2017년 7월 12일

3 개 추천

>> a = [0.203 0.506 0.167 0.904 1.671 5.247 0.037 0.679];
>> a(a>1)=1

추가 답변 (1개)

Jan Siegmund
Jan Siegmund 2020년 5월 27일
편집: Jan Siegmund 2020년 5월 27일

2 개 추천

There is also a matlab function doing this:
A = min(A,1);
It takes A if A is the minimum of the two and 1 if 1 is the minimum of the two.

댓글 수: 2

Tim Kuipers
Tim Kuipers 2020년 11월 30일
That doesn't work if A is an array. It gives an error
Walter Roberson
Walter Roberson 2020년 11월 30일
min(randn(3,3),1) works fine when I test it. Perhaps you accidentally defined min as a variable

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

카테고리

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

제품

질문:

2017년 7월 12일

댓글:

2020년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by