Logical mask for a concatenated series of numbers based on document length
Afficher commentaires plus anciens
I have a set of N documents, each of some maximum size M. Each document is of different length and contains a series of word features of size K. The end of the document is padded with zeros(K, 1) features up to maximum size. Therefore, my data is in a matrix of size (K, N*M).
For each document I compute some number H based on document size, giving me a vector of size (N, 1) of all the Hs. I only want to get the data for each document up to index H and then concatenate all those features together. So let's say N = 3, M = 100, K = 10, data, which is of dimensionality (10, 3*100), and H = (45, 30, 25) I would want to have result = [data(1:45) data(101:131) data(201:226)]. Is there a way to do this without a for loop? I want to make the code efficient.
edit: Sorry, I realized there is an easier way to ask my question. Say I have a long vector, data, a vector of start indices, st, and a vector of end indices, ed. I want to get data([st(1):ed(1) st(2):ed(2) st(3):ed(3)...]). Is there a way to do this?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices 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!