Calculate the remaining index of my data

조회 수: 2 (최근 30일)
muhammad ismat
muhammad ismat 2017년 9월 27일
댓글: muhammad ismat 2017년 9월 28일
If i have
x= 1 2
3 4
2 5
1 5
is the index of my data. i want to get on remaining of these index but not need index that have i=j i.e [ (1 1) (2 2) (3 3)(4 4)(5 5) and not need fliplr of x i.e [(2 1)(4 3)(5 2)(5 1)]. so i want to the result
result=
1 3
1 4
2 3
2 4
3 5
4 5
that should not contain fliplr of any index.
  댓글 수: 1
Rik
Rik 2017년 9월 27일
It is not clear what your question is. It sounds like you could solve your problem with logical indexing, or even find (and maybe a call to ismember(fliplr(A),A)), but without understanding your problem better I can't help you with actual code.

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2017년 9월 27일
Here is one way.
x= [1 2
3 4
2 5
1 5];
result = zeros(5*2,2);
ri = 1;
for ii=1:5
for jj = ii+1:5
result(ri,:) = [ii jj];
ri = ri+1;
end
end
isRowToRemove = ismember(result,x,'rows');
result(isRowToRemove,:) = [];
There is certainly a better way to pre-populate the array result with all possible row values than using the loops, but I got lazy.

추가 답변 (1개)

OCDER
OCDER 2017년 9월 27일
%Getting index of an arbitrary matrix
[x, y] = find(ones(5, 'logical'));
x = [x y];
%Remove index i == j
x(x(:,1) == x(:,2), :) = [];
%Get unique x,y and not those that are y,x
x = unique(sort(x, 2), 'rows');
x =
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by