필터 지우기
필터 지우기

comparing the maximum value of a matrix to the other values

조회 수: 7 (최근 30일)
SSG_newbiecoder
SSG_newbiecoder 2017년 12월 29일
댓글: SSG_newbiecoder 2018년 1월 29일
Hello, I have a question. I need to compare the maximum value in an array to the other elements in an array and check if it is greater than 1.2 times the other elements. How can I do this in matlab? I'd prefer it if it is a simple command since I'm already doing this within a loop. I know max will give me the maximum but how to compare it with the other elements?

답변 (2개)

KSSV
KSSV 2017년 12월 29일
A = randperm(10,5) ;
B = randperm(20,5) ;
iwant = max(A)/max(B)
fprintf('max of A is %f times to max of B\n',iwant)
  댓글 수: 4
SSG_newbiecoder
SSG_newbiecoder 2017년 12월 29일
I have an array X=[1 2.2 3.5 3.8 2.8 2.9]. Maximum is 3.8. But I need to check if this maximum is 1.2 times the other 5 elements in the array.
KSSV
KSSV 2017년 12월 29일
X=[1 2.2 3.5 3.8 2.8 2.9] ;
R = X./max(X) ;
idx = abs(R-1.2)<10^-3

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


Walter Roberson
Walter Roberson 2017년 12월 29일
If you want to know whether it is greater than 1.2 for all of the elements, then
if max(FirstArray) > 1.2 * max(SecondArray)
If you want to know whether it is greater than 1.2 for some element then
if max(FirstArray) > 1.2 * min(SecondArray)
I recommend that you explicitly comment the behavior you want when some of the values in the second array might be negative. Is -1.3 "greater than" 1.2 times -1 because the value has greater distance from 0 ?
  댓글 수: 5
Birdman
Birdman 2018년 1월 29일
Check my answer.
SSG_newbiecoder
SSG_newbiecoder 2018년 1월 29일
Or if you can suggest a method to find an array element that is 1.2 times that of the other elements in the array, that will solve the problem without all the above hassle

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by