Borrar filtros
Borrar filtros

Question regarding a find function(search for data)

2 visualizaciones (últimos 30 días)
Gimpy
Gimpy el 26 de Mayo de 2013
Hi, I have the following matrix:
data=[10 1 2 3; 11 4 5 6; 12 7 8 9; 17 4 5 6]
I want to do a query with the following matirx:
built a matrix base on the element value 10 and 17
lookfor=[10;17]
And I'm looking for the following result(values associate with 10 and 17 in this case)
anwser=[10 1 2 3; 17 4 5 6]
I'm looking for a dynamic anwser, data matrix and lookfor matrix will vary and be much more bigger.
thank you in advance for your precious anwsers.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 26 de Mayo de 2013
Editada: Azzi Abdelmalek el 26 de Mayo de 2013
out=[data(any(data==17,2),:);data(any(data==10,2),:)]
%or
out=data(any(ismember(data,lookfor),2),:)
  4 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 26 de Mayo de 2013
How did you find anwser=[10 1 22 33; 11 8 10 12]
the cyclist
the cyclist el 27 de Mayo de 2013
Looks like he wants to find rows that start with 10, and sum them into one row. Then find rows that start with 11, and sum them.

Iniciar sesión para comentar.

Más respuestas (1)

the cyclist
the cyclist el 26 de Mayo de 2013
Editada: the cyclist el 26 de Mayo de 2013
rowIndex = ismember(data(:,1),lookfor);
answer = data(rowIndex,:);

Categorías

Más información sobre File Operations 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