Calculate the remaining index of my data

4 次查看(过去 30 天)
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 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by