find intersect of a column against another column and extracting rows
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
liu James
el 25 de Jun. de 2017
Respondida: Image Analyst
el 25 de Jun. de 2017
I'm trying to compare two tables A & B and find intersections of the time within one column of A against the time column of B and then extract that row associated with that time in that column of A & B into another array/matrix in sequential order.
CUM='/Users/jl/Desktop/Test/rev2.xlsx';
xlsread(CUM);
date1=ans(:,1);
date2=ans(:,3);
CU1=ans(:,2);
CU2=ans(:,4);
A=[date1,CU1];
B=[date2,CU2];
C=intersect(A,B);
This is what I have and the function intersect (A,B) is only extracting rows that are the same in both columns. Is there another function that can do what I'm trying to do?
2 comentarios
Image Analyst
el 25 de Jun. de 2017
You forgot to attach rev2.xlsx. And I'm not sure what you want. intersect() gives you the indexes where the number is common to both A and B. Then you can extract those rows from one or both matrices. Isn't that what you want?
Respuesta aceptada
Image Analyst
el 25 de Jun. de 2017
This will do that:
D=[1,1;1,2;2,3;3,4;5,3]
F=[1,2;1,3;3,3;4,5]
commonNumbersInCol1 = intersect(D(:, 1), F(:, 1))
rowsInD = ismember(D(:, 1), commonNumbersInCol1)
rowsInF = ismember(F(:, 1), commonNumbersInCol1)
G = [D(rowsInD, :), F(rowsInF, 2)]
but what if there are not the same number of rows in both F and D? What if 1, and 3 occurred 3 times in D (like now), but 100 times in a different F? What then?
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!