Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Short question: Using the find command

1 visualización (últimos 30 días)
MiauMiau
MiauMiau el 28 de Dic. de 2012
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi
I have a matrix X with three columns, say column 1 stores attribute a, column 2 sotres attribute b, and column 3 stores attribute c. Attribute c is not unique (same value might appear in different lines). What I want to do is to create a matrix, such that for each specific value of c, it would show me in which lines of X it is to be find. Why can I not use the following line:
G = find(X(:,3) == unique(X(:,3)))
to do so? Thanks

Respuestas (2)

Andrei Bobrov
Andrei Bobrov el 28 de Dic. de 2012
[~,g1] = unique(X(:,3),'first');
G = sort(g1);

Jan
Jan el 28 de Dic. de 2012
You cannot use
find(X(:,3) == unique(X(:,3))), % !!! wrong
because X(:,3) and unique(X(:, 3)) have a different number of elements in general. The result of
[1,2,3] == [1,2,3,4]
cannot be defined easily.
As Andrei has suggested already, the 2nd output of unique() will help you to solve the problem.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by