Borrar filtros
Borrar filtros

Indexing values, selecting a range, and outputting values

3 visualizaciones (últimos 30 días)
g
g el 9 de Sept. de 2018
Editada: Stephen23 el 9 de Sept. de 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!

Respuesta aceptada

Stephen23
Stephen23 el 9 de Sept. de 2018
Editada: Stephen23 el 9 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by