Subsetting a row of a matrix according to conditions in another row

2 visualizaciones (últimos 30 días)
I have a matrix in which the first row is some kind of index (let's say ranging from 1 to 50) and the second row is some varible y, like this:
t = repmat(1:50,1,50)
M = [ t ; y ]
I want to extract those entries of y which correspond to a given subset of the indexes, like
y([such that the corresponding t entry = to some subset of 1:50])
Is there some efficient way to do it avoiding loops or heavy demanding scripts?
Thank you

Respuesta aceptada

Matt J
Matt J el 22 de Mzo. de 2023
y( ismember(t, subset) );

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by