필터 지우기
필터 지우기

How to find indices of elements but keep the order unchanged?

조회 수: 34 (최근 30일)
Maria
Maria 2014년 9월 6일
댓글: ibrahim Salim 2018년 2월 8일
Hi all,
I have a cell array ch_names of channel names and I would like to get indexes of certain channels that I have given in pickCh. I have done this as follows:
Idx = find(ismember(ch_names,pickCh));
However, this gives the indexes in increasing order. Is there any better way than using a loop to keep the order of the indexes as it is in pickCh?
Thank you already in advance!
Regards, Maria

채택된 답변

Roger Stafford
Roger Stafford 2014년 9월 6일
[tf,loc] = ismember(ch_names,pickCh);
[~,p] = sort(loc(tf));
idx = find(tf);
idx = idx(p);
(This assumes this are no repetitions in 'pickCh'. Otherwise there is ambiguity as to the proper ordering.)
  댓글 수: 1
ibrahim Salim
ibrahim Salim 2018년 2월 8일
Hello, I used this code but I'v changed the first line with : [tf,loc] = cellfun(@(subc) ismember(pickCh, subc,'rows'), ch_names); to seek about a specific row. This line was slow. could you please help me to speed up run time by using the same command or another one.
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Maria
Maria 2014년 9월 6일
Thanks a lot! This seems to work.
-Maria

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by