Filter löschen
Filter löschen

Calculate the remaining index of my data

4 Ansichten (letzte 30 Tage)
muhammad ismat
muhammad ismat am 27 Sep. 2017
Kommentiert: muhammad ismat am 28 Sep. 2017
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 Kommentar
Rik
Rik am 27 Sep. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 27 Sep. 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.

Weitere Antworten (1)

OCDER
OCDER am 27 Sep. 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

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by