Mapping values of two different-length vectors to index-vector

3 ビュー (過去 30 日間)
Shelli255
Shelli255 2018 年 11 月 26 日
コメント済み: Shelli255 2018 年 11 月 26 日
Hello,
I didn't know how to put my problem into a good google search... I could not find anything appropriate.
What I want to do is I have two vectors
a = [0 .07 .14 .21 .28 .35 .42 .5]
b = [0 .1 .2 .3 .4 .5]
I want to compare a and b in a way that I get an Index vector which would say that a(1) is between b(1) and b(2), i.e. this index would return i(1) = 1 because a(1) is between b(1) and b(2). For the next element in a it would return i(2) = 1, because a(2) is between b(1) and b(2). For a(3) it would return i(3) = 2, because a(3) is between b(2) and b(3), etc. How can i achieve this? Thank you in advance!
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 11 月 26 日
Ohh sorry your question is different, I did not read the second part.
But the logic is not clear for me..
i(1) = 1 because a(1) is between b(1) and b(2)
i(2) = 1, because a(2) is between b(1) and b(2)
i(3) = 2, because a(3) is between b(2) and b(3)...??.Here i(3)=2 and here b(2) and b(3)....in privious case b(1) abd b(2)

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 11 月 26 日
編集済み: Stephen23 2018 年 11 月 26 日
>> [~,X] = histc(a,b)
X =
1 1 2 3 3 4 5 6
  1 件のコメント
Shelli255
Shelli255 2018 年 11 月 26 日
thank you very much, kind sir!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by