How to extract the common values only between two variables?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a point file and a polyline file. I want to extract only the lines from the polyline file which contains the points from the other file. Can anyone please help me how to do it? I have attached the points and polyline file.
0 comentarios
Respuestas (2)
Image Analyst
el 14 de Dic. de 2020
Try setdiff() to find out what's not in the other set, and ismember() to find out what's common to both sets.
This may be instructive:
set1 = [1,3,32,19,4,21]
set2 = [2,4,19,25,32,40]
% Find the mismatches which are in set1 but not in set2
mismatches = setdiff(set1, set2)
% Find the mismatches which are in set2 but not in set1
mismatches = setdiff(set2, set1)
% Find out which numbers are in both set2 and in set1
[ia, ib] = ismember(set2, set1)
myMatches = set2(ia)
You'll see:
set1 =
1 3 32 19 4 21
set2 =
2 4 19 25 32 40
mismatches =
1 3 21
mismatches =
2 25 40
ia =
1×6 logical array
0 1 1 0 1 0
ib =
0 5 4 0 3 0
myMatches =
4 19 32
Can you see how to adapt it to your data? If not I'll do it for you.
KSSV
el 14 de Dic. de 2020
load Points.mat ;
load Polyline.mat ;
m = length(network) ;
n = length(sedsource) ;
P = cell(n,1) ;
iwant = cell(n,1) ;
for i = 1:n
P = [sedsource(i).X ;sedsource(i).Y];
for j = 1:m
L = [network(i).X ;network(i).Y];
idx = ismember(P',L','rows') ;
if idx~=0
iwant{i} = L ;
break
end
end
end
% plot for check
figure
hold on
for i = 1:n
plot(iwant{i}(1,:),iwant{i}(2,:))
plot(P{i}(1),P{i}(2),'*')
end
Ver también
Categorías
Más información sobre Large Files and Big Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!