Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

extracting columns with comparison

1 visualización (últimos 30 días)
MiauMiau
MiauMiau el 25 de Jun. de 2014
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi
Given I would have (as a toy example) a matrix A like:
A = [ 5 7 -5; 3 8 3; 2 9 2]
I would want to extract the indices of the pairs of columns which have the same y and z values but a negative x value of each other. So for the example this is true for the first and third column (the x values are 5 and -5 respectively, and the y value is 3 for both and the z value is 2 for both too). How would I do that?

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 25 de Jun. de 2014
Editada: Andrei Bobrov el 25 de Jun. de 2014
B = A;
B(1,:) = abs(B(1,:));
[a,~,c] = unique(B.','rows');
out = [accumarray(c,(1:numel(c))',[],@(x){x})';num2cell(a',1)];

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by