필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by