Create one matrix of different sized vectors

I have 10 different vectors containing time series data. All have different start dates corresponding to their first row and a different end date corresponding to their last row. How can I combine them into one large matrix with the full time line as the first vector and then the other vectors dropped in at their respective places in the time line with NaNs for the cells that have no data for that series in them? Thanks!

Answers (2)

data = nan(max_vector_length,10);
for ii = 1:10
data(1:size(pieceii),ii) = pieceii; %pseudoish code
end
How you have your vectors stored greatly affects how you insert them. Refer to this document:

2 Comments

Oh well, for instance one of the vectors does not match the long date vector until the 2,800th row. Then there are some dates in between that don't match. and then it stops five rows from the bottom. So i think i have to go row by row and match. I have a large matrix of 0s and 1's where the dates match, but i don't know how to get the data into the 1's positions. If that makes sense.
Ok. I think I completely misunderstood your question.. Could you edit your original question to include a small set of sample data (perhaps two vectors 5-10 elements long) the operation and the expected results.

Sign in to comment.

The code that finally worked:
datesvect=datewrkdy(['1-jan-' num2str(b_dyear)],[1:1: wrkdydif(['1/1/' num2str(b_dyear)],['12/31/' num2str(e_dyear)])]',0);
n_obsd = size(datesvect,1);
Lff_matrix = [datesvect nan(n_obsd, n_countries)];
for i_w=1:size(lff.ja,1)
aa = find(datesvect==lff.ja(i_w,1));
Lff_matrix(aa,9) = lff.ja(i_w,5);
end
I ended up running the last loop for each of the 10 vectors. I am sure there must be a more efficient way to do that. But it did work.

Asked:

on 21 Dec 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!