Dear all,
I have two arrays A and B consisting of floating point numbers. The size of array A is [104,1] and B is [641,1]. I want to compare each element of A with every element of B.
[A]=[0
2.527947992282320e-04
1.809924379782077e-04
....
]
[B]=[0
0.005
0.010
0.015
.....
]
Kindly help me.
Thanks in advance.

댓글 수: 1

Image Analyst
Image Analyst 2018년 4월 10일
What does "compare" mean to you? Do you want to check for "equality"? Do you want to know which is greater or lesser? Do you want to know the distance (difference) between corresponding (or all) elements from each other? Please define "compare".

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

답변 (3개)

KSSV
KSSV 2018년 4월 10일

0 개 추천

Read about ismemebrtol

댓글 수: 1

Abhinav Srivastava
Abhinav Srivastava 2018년 4월 10일
I am using MATLAB version 2013. Here this tool is not present.

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

A Mackie
A Mackie 2018년 4월 10일
편집: Guillaume 2018년 4월 10일

0 개 추천

A-B'
will generate a 104x641 matrix where each row is a value of A minus each individual value of B.
The ' operator takes the transpose of the vector B, allowing you to use implicit expansion. This will only work with later versions of MATLAB I believe.

댓글 수: 5

In case B contains complex numbers using .' (plain transpose) would be safer than ' (which is the conjugate transpose).
In earlier versions of matlab (pre R2016b), you'd use bsxfun instead of implicit expansion
bsxfun(@minus, A, B.')
Abhinav Srivastava
Abhinav Srivastava 2018년 4월 10일
I tried above two options but they didn't worked. I have to compare elements of A with B and group them within intervals present in B. The intervals in B can be interpreted as B = 0:0.01:1;
Guillaume
Guillaume 2018년 4월 10일
편집: Guillaume 2018년 4월 10일
but they didn't worked
The bsxfun version is guaranteed to work (as long as you have enough memory to store the result). Now, it may not give the result you expected but that's because you've not explained clearly what you want.
I have to compare elements of A with B and group them within intervals present in B
So, are you trying to find the at which k index of B the value A(i) is between B(k) and B(k+1)?
Abhinav Srivastava
Abhinav Srivastava 2018년 4월 10일
Yes I am trying to find index of k of B for which A(i) lies between B(k) and B(k+1). I think for that we need to check whether A(i) lies between B(k) and B(k+1)
Guillaume
Guillaume 2018년 4월 10일
"Yes I am trying to find index..."
Then I have answered that...

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

Guillaume
Guillaume 2018년 4월 10일
편집: Guillaume 2018년 4월 10일

0 개 추천

If you're trying to find at which k index of B the value A(i) is between B(k) and B(k+1), then:
[~, idx] = histc(A, B) %in R2013. Newer versions of matlab have much better functions for that

카테고리

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

질문:

2018년 4월 10일

댓글:

2018년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by