Borrar filtros
Borrar filtros

How do i find if variable k is element of an array?

317 visualizaciones (últimos 30 días)
ME
ME el 17 de Mzo. de 2015
Respondida: akshatha nayak el 24 de Mzo. de 2019
I have an array of 90x2 and may variable is 1x2. i want to set an if statment which checks if k == array or k is an element of array. I am aware there is ismember function but I cant seem to make that work for me
  1 comentario
David Young
David Young el 17 de Mzo. de 2015
It doesn't make sense to check if k == array, because they are different sizes.
k can't be an element of the array, because each element of the array is a scalar, but k is 1x2. Do you want to check whether k is a row of the array?
What actually goes wrong when you use ismember? Have you tried the 'rows' option?

Iniciar sesión para comentar.

Respuestas (2)

Stephen23
Stephen23 el 17 de Mzo. de 2015
Editada: Stephen23 el 17 de Mzo. de 2015
The description is ambiguous as to what "is an element of array" means for a two element vector, but I assumed that the desired end result is to check if any matrix row matches the variable.
You can use ismember to solve this, reading the documentation to get the right argument order:
>> A = [0,1;2,3;4,5;6,7;8,9];
>> ismember([4,5],A,'rows')
ans =
1
>> ismember([99,100],A,'rows')
ans =
0

akshatha nayak
akshatha nayak el 24 de Mzo. de 2019
I want to check whether the data that is present in sheet 1 of excel is same as sheet 2 of excel of same file name tht is testdata1.xls can any 1 help me to solve this problem

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by