Borrar filtros
Borrar filtros

help with nested indexing

2 visualizaciones (últimos 30 días)
Manolis Michailidis
Manolis Michailidis el 3 de Sept. de 2015
Comentada: per isakson el 3 de Sept. de 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' );

Respuesta aceptada

per isakson
per isakson el 3 de Sept. de 2015
Editada: per isakson el 3 de Sept. de 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 );

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by