How to compare in matlab
Mostrar comentarios más antiguos
Hi,
I have an array with 2*100 size. i want to check that a variable k with the 1st row of the array that k is equal or not to any value in the 1st row.
A=[3 4 6 3 5 4 2 56 7 7; 56 34 2 4 6 7 7 78];
variable k=3;
so i want to check k with A(1,1);A(1,2);A(1,3);......;A(1,n)
Respuestas (5)
Vieniava
el 10 de Feb. de 2011
Try this:
TestA=( A(1,:) == k);
TestA is a logic vector or this
TestVec=find( A(1,:) == k);
TestVec - is a vector containg positions of matched values
2 comentarios
Sukumar Palo
el 10 de Feb. de 2011
Vieniava
el 10 de Feb. de 2011
use TestVec - TestVec would consist of indices of matched values ( A(1, TestVec) = k ).
Sukumar Palo
el 10 de Feb. de 2011
1 voto
1 comentario
Oleg Komarov
el 10 de Feb. de 2011
not clear at all...
Walter Roberson
el 13 de Feb. de 2011
ismember(k, TestA(1,:))
Andreas Goser
el 10 de Feb. de 2011
I suggest comparing the difference of A in k with a very small number:
f=abs(k-A(1,:))<2*eps
This avoids a couple of numerical surprises...
1 comentario
Jan
el 13 de Feb. de 2011
What about "2 * eps(k)" to consider k'th magnitude?
Bo
el 13 de Feb. de 2011
0 votos
Any(A(1,:)==k)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!