Search in two columns (Tables)

2 visualizaciones (últimos 30 días)
Manuel Valenciano
Manuel Valenciano el 20 de Jun. de 2016
Respondida: Peter Perkins el 3 de Ag. de 2016
Hi, I'm going to explain my problem with a small example of my real problem. My real problem has a bigger size than the following example.
I have two tables with data: Table1_example:
Table2_example:
Table1_example1 and Table1_example2 are the same variables that Table2_example1 and Table2_example2 (Categorical data).
I want to search the values in Table1_example in Table2_example and obtein the following final table:
TableObjective_example:
Thank you for your help.
  1 comentario
Manuel Valenciano
Manuel Valenciano el 20 de Jun. de 2016
I try to use the function join but I have an error:
Error using table/join (line 111)
The key variable for B must have unique values.

Iniciar sesión para comentar.

Respuestas (1)

Peter Perkins
Peter Perkins el 3 de Ag. de 2016
I'm not 100% sure I've understood the operation you want to do, but it sounds like you want to find the rows in table 2 whose example1 and example2 values match the example1 and example2 values in table 1, and get those rows from table 2. You can do that using something like
i = ismember(table2(:,{'example1' 'example2'}),table1(:,{'example1' 'example2'});
table3 = table2(i,:);
That assumes all combinations are unique. If the goal is more general than that, then I think Manuel is on the right track with some form of join.

Categorías

Más información sobre Large Files and Big Data 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