Storing vectors of different length in one single vector
古いコメントを表示
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!
採用された回答
その他の回答 (2 件)
Shiva Arun Kumar
2012 年 2 月 9 日
0 投票
Walter Roberson
2012 年 2 月 9 日
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
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!