Borrar filtros
Borrar filtros

Comapre arrays of two cells and keep similar arrays

2 visualizaciones (últimos 30 días)
BN
BN el 8 de Abr. de 2020
Comentada: Ameer Hamza el 8 de Abr. de 2020
Hi
I have 2 cells, A and B; each one containing tables. In the tables, there are a "lat" and "lon" columns. Some "lat" and "lon" columns are similar in both cells. Now I want to compare the table by table each A and B, then in the cell of A save only similar tables (based on "lat" and "lon").
"lat" and "lon" of both tables need to be similar.
Thanks

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 8 de Abr. de 2020
Try this
load('A.mat')
load('B.mat')
A_lat_lon = cell2mat(cellfun(@(x) {[x.lon(1) x.lat(1)]}, A)');
B_lat_lon = cell2mat(cellfun(@(x) {[x.lon(1) x.lat(1)]}, B)');
idx1 = ismember(A_lat_lon, B_lat_lon, 'rows');
idx2 = ismember(B_lat_lon, A_lat_lon, 'rows');
new_A = A(idx1);
new_B = B(idx2);
  2 comentarios
BN
BN el 8 de Abr. de 2020
Thanks again, That's what I needed. Many thanks.
Ameer Hamza
Ameer Hamza el 8 de Abr. de 2020
Glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by