Filter löschen
Filter löschen

Indexing values, selecting a range, and outputting values

3 Ansichten (letzte 30 Tage)
g
g am 9 Sep. 2018
Bearbeitet: Stephen23 am 9 Sep. 2018
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!

Akzeptierte Antwort

Stephen23
Stephen23 am 9 Sep. 2018
Bearbeitet: Stephen23 am 9 Sep. 2018
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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by