Finding Upper and Lower Indexes

4 ビュー (過去 30 日間)
Aninda Maji
Aninda Maji 2021 年 2 月 20 日
回答済み: Matt J 2021 年 2 月 20 日
Hello,
I have 2 vectors:
A = [1;2;3;4;5;8];
B = [3.5;6;2];
I would like to find the lower and upper indexes and store in another array C. C should be =
C = [3 4;5 6;2 0]; where first column represent the lower index and second column represent the upper index. In case an exact data is found lower index gives the index directly]
for example: 3.5 is between 3 & 4 so in C first row becomes 3 4.
Could you please help me in this?
Thanks.

回答 (1 件)

Matt J
Matt J 2021 年 2 月 20 日
A = [1;2;3;4;5;8];
B = [3.5;6;2];
c=interp1(A,A,B,'previous');
C=[c(:),c(:)+1]
C = 3×2
3 4 5 6 2 3

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by