split a vector and save it as a cell (1xN)
Afficher commentaires plus anciens
I have three vectors:
- vector_1 has numbers from 69 to 98;
- vector_2 has numbers from 69 to 78 and 82 to 98;
- vector_3 has numbers 69 to 78, 82 to 89 and 91 to 98.
I would like to subdivide the vector into a cell:
- for vector_1: I need to get a cell with numbers 69 to 98 (cell 1x1);
- for vector_2: I need to get a cell with the numbers 69 to 78 and 82 to 98 (cell 1x2);
- for vector_3: I need to get a cell with the numbers 69 to 78, 82 to 89 and 91 to 98 (cell 1x3).
1 commentaire
Dyuman Joshi
le 14 Juil 2023
"Is there any possibility to create a more generic code?"
The data you have is stored dynamically, which is hard to work with. There is possibility of improvement from the given answer, but you will have to do the same thing for each vector manually.
You can store the data in a cell array and run a for loop through each element.
How many vectors are you dealing with? What do you want to do this the output?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numeric Types dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!