Is there a way to use setdiff or any function to compare two data sets within a range of each other?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JChemPhD
el 30 de Mzo. de 2015
Comentada: Image Analyst
el 30 de Mzo. de 2015
I have two large data sets that are equal in dimensions but not in variables. Also the variables are similar but not exact so setdiff returns every value in the smaller data set. I'd like to know is there a way to add some range into the setdiff function like setdiff(A,B<+-2,B<+-2)?
2 comentarios
Image Analyst
el 30 de Mzo. de 2015
Can you just do setdiff(B, A) instead? Can you give a small example?
Respuesta aceptada
Sean de Wolski
el 30 de Mzo. de 2015
Starting in R2015a, there is a function ismembertol. You can use this and the set diff logic on idx.
0 comentarios
Más respuestas (1)
Image Analyst
el 30 de Mzo. de 2015
Since every row needs to be compared to every other row in the other matrix in a range of values, you can use (and may have to) use a double for loop with an if statement inside. Might not be a one-liner but at least it's straightforward and intuitive.
7 comentarios
Image Analyst
el 30 de Mzo. de 2015
Try this:
A = [...
1.21 0.550
9.78 0.989
13.67 0.947]
B =[...
1.19 0.45
13.55 1.05]
[rowsA, columnsA] = size(A)
[rowsB, columnsB] = size(B)
different = false(rowsA, rowsB);
tolerance = 2;
for rowa = 1 : rowsA
thisRowA = A(rowa, :); % Extract just one row.
% Now check all rows of B to see if they are any that are different.
for rowb = 1 : rowsB
thisRowB = B(rowb, :); % Extract just one row.
% Check if rowb of B is different than rowa of A
itsDifferent = any(abs(thisRowB - thisRowA) > tolerance);
% Record whether it's different or not.
different(rowa, rowb) = itsDifferent;
end
end
different
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!