remove non-unique columns even if the sign has changed
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
LC
el 4 de Feb. de 2025
Comentada: Les Beckham
el 4 de Feb. de 2025
I have a 76x16 matrix. Some of the data is repeated and I want to remove repeated columns, which I have tried to do below. However, the numbers are the same but the sign has changed, e.g. columns 8 and 14 are the same data but the signs are reversed (where 8 is +ve, 14 is -ve etc), which my code doesn't acocunt for. The +ve/-ve matters so I cant just abs() the dataset.
I want to keep the first occurence of the repeated columns, where I should be left with 6 columns of data. Can anybody help?
mlag= unique(newca1.','rows','stable').'
mlag(:,max(mlag) == 0) = [];
0 comentarios
Respuesta aceptada
Les Beckham
el 4 de Feb. de 2025
Perhaps this?
load newca.mat
[~, icol, ~] = unique(abs(newca1).', 'rows', 'stable')
mlag = newca1(:,icol)
2 comentarios
Más respuestas (1)
Steven Lord
el 4 de Feb. de 2025
Editada: Steven Lord
el 4 de Feb. de 2025
Make a copy of newca1, let's call it M. Multiply each column of M whose first element is negative by -1. This way if you think of your columns as vectors, they're all pointing "right" (towards +Inf along the x axis, if this were a 2-dimensional problem.) Call unique on M and ask not only for the unique rows but also the indices of the unique rows. Use the indices to extract the corresponding columns of newca1.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!