indexing of an array of index

4 vues (au cours des 30 derniers jours)
Rica
Rica le 8 Nov 2012
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

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 8 Nov 2012
Modifié(e) : Andrei Bobrov le 8 Nov 2012
index = bsxfun(@plus,ind(:),-2:2);
OR full solution
index = bsxfun(@plus,min(abx(bsxfun(@minus,numdates(:),date_l(:).'))),(-2:2).');

Plus de réponses (1)

Rica
Rica le 8 Nov 2012
that is really great. how do find in google something like this? i try it to find it myself before i asked the question...
thanks again

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by