Checking a matrix for duplicates in specific row, removing the respective columns
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Claudius Simon Appel
am 6 Aug. 2020
Kommentiert: Claudius Simon Appel
am 6 Aug. 2020
So, I try to explain this.
I have a two-row matrix of values, [x;y], f.e.
x=[1 2 2 3 4 5 6 6 7]
y=[1 2 3 4 5 6 7 7 8]
being merged into the matrix:
d= [1 2 2 3 4 5 6 6 7;
1 2 3 4 5 6 7 7 8]
I then want to check this matrix for repeats in the first row & remove the respective columns, while saving the x values of the columns being removed as a seperate vector. So Output should be something like:
d=[1 3 4 5 7;
1 3 4 5 8]
x_cut=[2 6]
It should be noted that this would have to scan for multiple repeats of different values, as shown above.
Thank you.
Have a great day & stay safe
Claudius Appel
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 6 Aug. 2020
Bearbeitet: Bruno Luong
am 6 Aug. 2020
d= [1 2 2 3 4 5 6 6 7;
1 2 3 4 5 6 7 7 8]
dd = diff([nan,d(1,:),nan])==0;
remove = dd(1:end-1) | dd(2:end)
x_cut = unique(d(1,remove),'stable')
d(:,remove) = []
3 Kommentare
Bruno Luong
am 6 Aug. 2020
Bearbeitet: Bruno Luong
am 6 Aug. 2020
d= [1 2 2 3 4 5 6 6 7;
1 2 3 4 5 6 7 7 8]
dd = diff([nan,d(1,:),nan])==0;
remove = dd(1:end-1) | dd(2:end);
cut = d(:,remove)
keep = d(:,~remove) % rename keep to d if you like
Or if yoy want to get cut from x_cut
dd = diff([nan,d(1,:),nan])==0;
remove = dd(1:end-1) | dd(2:end)
x_cut = unique(d(1,remove),'stable')
cut = d(:,ismember(d(1,:), x_cut))
d(:,remove) = []
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!