MATLAB: Appending arrays of different length

appendMATLAB

Dear all,
My goal is to have an array with 8760 rows (number of hours in a year). Each row should now indicate the day-number of each month, which will mean that I have in the first rows 23x the number 1, then 23 times the number 2, ….. till the end of the month 23 times the number 31 (for January). Then it begins again with 23 times 1,…., till the end of February with 23 times 28.
I have created the following code:
n=23 ;
x31=(1:31)';
x30=(1:30)';
x28=(1:28)';
Jan=repmat(x31,1,n)';
Jan=Jan(:)';
Feb=repmat(x28,1,n)';
Feb=Feb(:)';
Mar=repmat(x31,1,n)';
Mar=Mar(:)';
Apr=repmat(x30,1,n)';
Apr=Apr(:)';
Mai=repmat(x31,1,n)';
Mai=Mai(:)';
Jun=repmat(x30,1,n)';
Jun=Jun(:)';
Jul=repmat(x31,1,n)';
Jul=Jul(:)';
Aug=repmat(x31,1,n)';
Aug=Aug(:)';
Sep=repmat(x30,1,n)';
Sep=Sep(:)';
Okt=repmat(x31,1,n)';
Okt=Okt(:)';
Nov=repmat(x30,1,n)';
Nov=Nov(:)';
Dez=repmat(x31,1,n)';
Dez=Dez(:)';
Now, I would like to append the rows to have one big array of 8760 rows (= time.day(8760,1)) that each indicate the day-number.
However, the code cat() does not allow me to append two arrays of different length.
I am very pleased for a hint.
With kind regards

Best Answer

didn't quite understand what output you really are looking for, but this shows how to use cat(). (note that with n=23, the result is not 8760 rows but 8395; do you want n=24?).
vertcat() and horzcat() are versions of cat() with implicit directions, so these three lines are all equivalent:
longList = cat(1, Jan',Feb',Mar',Apr',Mai',Jun',Jul',Aug',Sep',Okt',Nov',Dez'); % specify dimension in first input
longList1 = vertcat(Jan',Feb',Mar',Apr',Mai',Jun',Jul',Aug',Sep',Okt',Nov',Dez');
longList2 = horzcat(Jan,Feb,Mar,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez)';
always useful to scroll to the bottom of the help pages for the 'See Also' section for any function :)