Indexing values, selecting a range, and outputting values

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Stephen23
Stephen23 il 9 Set 2018
Modificato: Stephen23 il 9 Set 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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by