フィルターのクリア

Indexing values, selecting a range, and outputting values

3 ビュー (過去 30 日間)
g
g 2018 年 9 月 9 日
編集済み: Stephen23 2018 年 9 月 9 日
Let's say I have two sets of data.
A = [1 2 3 4 5 6 7 8 9 10]
B = [4 5 2 8 9 0 1 0 4 6 ]
Let's say I only care about values of B for a given range in A (for example 4<= A <=7) and want the corresponding values of B in a matrix C = [8 9 0 1].
How do I map the values of B to values in A, select the given range in A, then output the correct B values to matrix C? Thanks!

採用された回答

Stephen23
Stephen23 2018 年 9 月 9 日
編集済み: Stephen23 2018 年 9 月 9 日
Use logical indexing:
>> A = [1 2 3 4 5 6 7 8 9 10];
>> B = [4 5 2 8 9 0 1 0 4 6 ];
>> C = B(A>=4 & A<=7)
C =
8 9 0 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by