List of increasing integers
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tony Haines
le 22 Fév 2024
Commenté : Dyuman Joshi
le 22 Fév 2024
I have a list of dimensions given by the row vector as follows
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1624943/image.png)
I would like to associate with this vector, a list of increasing integers such that each size in 'dim' corresponds with an exact number of integers like this:
int = [ 1 2 , 3 4, 5 6 7 8, 9 10, 11 12, 13 14, 15 16, 17 18, 19 20, 21 22, 23 24, 25 26]
I grouped the integers just to indicate that a dim=4 corresponds to 5 6 7 8. and the rest just has two integers.
Thanks.
0 commentaires
Réponse acceptée
Dyuman Joshi
le 22 Fév 2024
dim = [2 2 4 2 2 2 2 2 2 2 2 2]
int = 1:sum(dim)
out = mat2cell(int, 1, dim)
2 commentaires
Plus de réponses (1)
Les Beckham
le 22 Fév 2024
Are you sure that is what you want? It doesn't seem very useful.
dim = [2 2 4 2 2 2 2 2 2 2 2 2]
int = 1:sum(dim)
int(end)
Voir également
Catégories
En savoir plus sur Elementary Math 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!