Borrar filtros
Borrar filtros

comparing floating point numbers

10 visualizaciones (últimos 30 días)
Abhinav Srivastava
Abhinav Srivastava el 10 de Abr. de 2018
Comentada: Guillaume el 10 de Abr. de 2018
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 comentario
Image Analyst
Image Analyst el 10 de Abr. de 2018
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".

Iniciar sesión para comentar.

Respuestas (3)

KSSV
KSSV el 10 de Abr. de 2018
Read about ismemebrtol
  1 comentario
Abhinav Srivastava
Abhinav Srivastava el 10 de Abr. de 2018
I am using MATLAB version 2013. Here this tool is not present.

Iniciar sesión para comentar.


A Mackie
A Mackie el 10 de Abr. de 2018
Editada: Guillaume el 10 de Abr. de 2018
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 comentarios
Abhinav Srivastava
Abhinav Srivastava el 10 de Abr. de 2018
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 el 10 de Abr. de 2018
"Yes I am trying to find index..."
Then I have answered that...

Iniciar sesión para comentar.


Guillaume
Guillaume el 10 de Abr. de 2018
Editada: Guillaume el 10 de Abr. de 2018
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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by