My answer covers two cases:
P
(prices) and PD
(pricedates) are tables
P
(prices) and PD
(pricedates) are arrays
Here is the code:
% generate some sample data
price = [1;2;3;4;5];
pricedate1 = [11;12;13;14;15;16];
pricedate2 = pricedate1+10;
pricedate3 = pricedate2+10;
% create sample table
P = table(price);
PD = table(pricedate1,pricedate2,pricedate3);
% this is the code if P and PD are tables
TMP = repmat(P{:,1},1,size(PD,1))';
T = [repmat(PD,size(P,1),1),table(TMP(:),'VariableNames',{'price'})]
% create sample arrays
P = price;
PD = [pricedate1,pricedate2,pricedate3];
% this is the code if P and PD are arrays
TMP = repmat(P,1,size(PD,1))'
T = [repmat(PD,size(P,1),1), TMP(:)]
It is possible to write it in a single line to to eliminate the TMP
-variable.
For data of type table
:
T = [repmat(PD,size(P,1),1),table(subsref(repmat(P{:,1},1,size(PD,1))',struct('type','()','subs',{{':'}})),'VariableNames',{'price'})]
For data of type array
:
T = [repmat(PD,size(P,1),1),subsref(repmat(P,1,size(PD,1))',struct('type','()','subs',{{':'}}))];
I admit, that the single line looks quite cryptic.