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

3 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Matt J
Matt J le 22 Mar 2023
y( ismember(t, subset) );

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by