indexing of an array of index
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi!
% for l=1:length(date_l)
[~, ind(l)] = min(abs(numdates-(date_l(l))));
end
i get the array ind
How could i get the ind of the minimum and the two index before and the two after ?
what should i change here [~,ind(l)] to get the result?
Thank you
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 8 de Nov. de 2012
Editada: Andrei Bobrov
el 8 de Nov. de 2012
index = bsxfun(@plus,ind(:),-2:2);
OR full solution
index = bsxfun(@plus,min(abx(bsxfun(@minus,numdates(:),date_l(:).'))),(-2:2).');
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!