How to compare two non-integer value together?

조회 수: 6 (최근 30일)
Malahat Mehraban
Malahat Mehraban 2022년 1월 7일
답변: Image Analyst 2022년 1월 7일
Hi all,
I have two matrix with non-integer values (they have been attached). I want to compare them and find which numbers are greater than eighty percent of their corresponding values. if the corresponding value is greater returns true and if it is less than 80% returns false.
For instance: x1=85.36 and x2=73.52; I want to compare x1 and x2 and find that is the second one greater than 80% of x1 or not.
Thank you in advance for any suggestions.
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 1월 7일
prctile()?
Malahat Mehraban
Malahat Mehraban 2022년 1월 7일
No. For instance:
x1=85.36 and x2=73.52; I want to compare x1 and x2 and find that is the second one greater than 80% of x1 or not.

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

답변 (3개)

DGM
DGM 2022년 1월 7일
Your example arrays are identical, and I don't really know which one you're trying to compare to which. Consider the example using two arrays. Here, I use A as the reference, and test to see if the elements of B are greater than 80% of the corresponding elements of A.
A = 10*rand(1,10);
B = A - 2*rand(1,10);
bar([A.' B.'])
legend({'A','B'})
Bisgt80pA = B>(A*0.8)
Bisgt80pA = 1×10 logical array
1 0 0 0 0 1 1 0 1 1

Steven Lord
Steven Lord 2022년 1월 7일
Is what you're trying to do as simple as just multiplication and relational operators?
x1=85.36;
x2=73.52;
x2 >= 0.8*x1
ans = logical
1

Image Analyst
Image Analyst 2022년 1월 7일
Do you mean, if they're vectors:
logicalIndexes = x2 > (0.80 * x1); % or
linearIndexes = find(logicalIndexes);
Or if they're scalars.
result = x2 > (0.80 * x1) % Returns true or false.

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by