Azzera filtri
Azzera filtri

Calculate the remaining index of my data

4 visualizzazioni (ultimi 30 giorni)
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 Commento
Rik
Rik il 27 Set 2017
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.

Accedi per commentare.

Risposta accettata

the cyclist
the cyclist il 27 Set 2017
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.

Più risposte (1)

OCDER
OCDER il 27 Set 2017
%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

Categorie

Scopri di più su Structures in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by