help with nested indexing

5 vues (au cours des 30 derniers jours)
Manolis Michailidis
Manolis Michailidis le 3 Sep 2015
Commenté : per isakson le 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' );
  1 commentaire
per isakson
per isakson le 3 Sep 2015
zeropad &nbsp???

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 3 Sep 2015
Modifié(e) : per isakson le 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 );

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by