Locate array element within limits given by another array

Probably quite easy but I don't know how to get it... I would like to find the floor of the position of each of the elements (positive decimal numbers) of one array in another array. In the second array the difference between consecutive elements is 2 always. For example: a=[3.45 8.99 10.02] b=[1.03 3.03 5.03 7.03 9.03 11.03 13.03] where what I want to get is c=[2 4 5]

 採用された回答

Sean de Wolski
Sean de Wolski 2015 年 11 月 30 日

0 投票

c = discretize(a,b)
c =
2 4 5
If you're running an older release without discretize, histc will do the same thing:
[~,c] = histc(a,b)

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2015 年 11 月 30 日

0 投票

a=[3.45 8.99 10.02];
b=[1.03 3.03 5.03 7.03 9.03 11.03 13.03];
[~,~,out] = histcounts(a,b);
Dana
Dana 2015 年 11 月 30 日

0 投票

Many thanks to both!

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2015 年 11 月 30 日

回答済み:

2015 年 11 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by