Storing vectors of different length in one single vector
Afficher commentaires plus anciens
Hello, hope you can help me out here...
I have a for-loop which produces with every loop a vector of values. The vectors it produces can have different lengths (for example, the vector in the first round has 10 values, in the second round 15, in the third 2...). In the end I'd like to store the values of these vectors in one single vector, but i really don't know how to best do it.
Thanks a lot in advance!
Réponse acceptée
Plus de réponses (2)
Shiva Arun Kumar
le 9 Fév 2012
0 votes
Walter Roberson
le 9 Fév 2012
The problem isn't so much storing the variable-length information: the problem is in getting the information out afterwards.
You need to store one of:
- the location of the start of each section
- the length of each section
- a unique marker between sections that cannot occur in the data itself
If you choose to store length information, you can store it separately, or you can prefix each segment with the segment length.
For example:
vector_of_data = [];
for k = 1 : whatever
newdata = as appropriate
vector_of_data = [vector_of_data length(newdata) newdata];
end
Catégories
En savoir plus sur Loops and Conditional Statements 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!