help with nested indexing

조회 수: 1 (최근 30일)
Manolis Michailidis
Manolis Michailidis 2015년 9월 3일
댓글: per isakson 2015년 9월 3일
Hi, my problem is not difficult but i am getting confused about it. So i have two vectors of indexes Nzlocs and locs
Nzlocs=[113 664 853 1236 2035];
locs=[113 202 296 403 546 606 664 812 853 909 999 1099 1189 1236 1278 1366 1460 1546 1595 1634 1722 1809 1896 1987 2035 2072 2159 2246 2333 2422 2498 2590 2674 2760 2854 2939];
and i want to find when this indexes are equal so i can finally locate my needed vector. The problem is that one vector has indexes of the other , for example the value 113 is the 1st so it will be 1 , the 664 7th so 7 etc. I wrote this code but i get an error that i exceed dimensions, note that zeropad is my custom function that performs zeropading to the needed vector so that it have same length as the other. So how can i do it, any ideas? thanks in advice.
fidx=arrayfun(@find,zeropad(Nzlocs,locs),locs ,'UniformOutput' );
  댓글 수: 1
per isakson
per isakson 2015년 9월 3일
zeropad &nbsp???

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

채택된 답변

per isakson
per isakson 2015년 9월 3일
편집: per isakson 2015년 9월 3일
One way
[~,ixb] = ismember( Nzlocs, locs )
ixb =
1 7 9 14 25
and a way using arrayfun and find
fidx = arrayfun(@(x) find(x==locs), Nzlocs, 'UniformOutput', true );

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by