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!