help with nested indexing

10 views (last 30 days)
Manolis Michailidis
Manolis Michailidis on 3 Sep 2015
Commented: per isakson on 3 Sep 2015
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' );

Accepted Answer

per isakson
per isakson on 3 Sep 2015
Edited: per isakson on 3 Sep 2015
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 );

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!