How do I split a vector into parts using indexes?
42 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
David Haydock
le 4 Oct 2022
Réponse apportée : Stephen23
le 4 Oct 2022
I have a vector, say
x = 1:100;
and I have a vector that is indexes within the range of the size of x, say,
y=[10,40,60];
I want to cut up x so that I get the three vectors:
x1 = x(1:y(1));
x2 = (y(1)+1:y(2));
x3 = (y(2)+1:y(3));
I tried to use a loop but there is indexing errors due to Matlab indexing starting at 1.
Help appreciated.
0 commentaires
Réponse acceptée
Stephen23
le 4 Oct 2022
x = 1:100;
y = [10,40,60];
C = mat2cell(x(1:y(end)),1,diff([0,y]))
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!