필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Short question: Using the find command

조회 수: 1 (최근 30일)
MiauMiau
MiauMiau 2012년 12월 28일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 12월 28일
[~,g1] = unique(X(:,3),'first');
G = sort(g1);

Jan
Jan 2012년 12월 28일
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.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by