Info

This question is closed. Reopen it to edit or answer.

extracting columns with comparison

1 view (last 30 days)
MiauMiau
MiauMiau on 25 Jun 2014
Closed: MATLAB Answer Bot on 20 Aug 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?

Answers (1)

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

Community Treasure Hunt

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

Start Hunting!