indexing of an array of index

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

 采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-11-8
编辑:Andrei Bobrov 2012-11-8
index = bsxfun(@plus,ind(:),-2:2);
OR full solution
index = bsxfun(@plus,min(abx(bsxfun(@minus,numdates(:),date_l(:).'))),(-2:2).');

更多回答(1 个)

Rica
Rica 2012-11-8

0 个投票

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

类别

在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by