Split array based on given indices

9 vues (au cours des 30 derniers jours)
Mariella Dreißig
Mariella Dreißig le 15 Août 2019
I want to split one array into two based on given indices. Specifically, have two arrays, one array A with data (3 columns) and one B with indices.
eg A = [10 11 12 13 14 15 16 17 18 19 20], B = [3 4 5 8 9 10]
As a result, I want two new arrays C and D where C includes all values in A on given indices in B and D including the rest.
eg C = [12 13 14 17 18 19], D = [10 11 15 16 20]
For now, I'm having a loop (check for i in B with ismember and append value in A to array C/D accordingly) but since I have a lot of data, it takes quite long. Any help is appreciated, I know that there is a arrayfunction for everything in matlab.

Réponse acceptée

madhan ravi
madhan ravi le 15 Août 2019
C=A(B)
D=setdiff(A,C)
  1 commentaire
Mariella Dreißig
Mariella Dreißig le 15 Août 2019
Modifié(e) : Mariella Dreißig le 15 Août 2019
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by