フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

extracting columns with comparison

1 回表示 (過去 30 日間)
MiauMiau
MiauMiau 2014 年 6 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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?

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2014 年 6 月 25 日
編集済み: Andrei Bobrov 2014 年 6 月 25 日
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!

Translated by