Borrar filtros
Borrar filtros

Calculate the remaining index of my data

4 visualizaciones (últimos 30 días)
muhammad ismat
muhammad ismat el 27 de Sept. de 2017
Comentada: muhammad ismat el 28 de Sept. de 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 comentario
Rik
Rik el 27 de Sept. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 27 de Sept. de 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.

Más respuestas (1)

OCDER
OCDER el 27 de Sept. de 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

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by