You may try out my Pivot/unPivot submission, I created it to manage time series as you pointed out. A1 = {'code','name' ,'date','price'
13 ,'Honda' ,734530, 1
13 ,'Honda' ,734531, 1.1
14 ,'Yamaha',734530, 0.5
14 ,'Yamaha',734531, 0.52};
B1 = Pivot(A1(2:end,[3,1,4]));
B1 =
NaN 734530 734531
13 1 1.1
14 0.5 0.52
[unCod,idx] = unique([A1{2:end,1}]);
[tf,loc] = ismember(B1(2:end,1),unCod);
A1(idx(loc)+1,2)
ans =
'Honda'
'Yamaha'
- 2nd case - cell array (keeping names and dates as strings)
A2 = {'code','name' ,'date' ,'price'
13 ,'Honda' ,'27-Jan-2011', 1
13 ,'Honda' ,'28-Jan-2011', 1.1
14 ,'Yamaha','27-Jan-2011', 0.5
14 ,'Yamaha','28-Jan-2011', 0.52};
B2 = Pivot(A2(2:end,[3,2,4]))
B2 =
[ NaN] '27-Jan-2011' '28-Jan-2011'
'Honda' [ 1] [ 1.1]
'Yamaha' [ 0.5] [ 0.52]
Difference in memory usage:
whos B1 B2
Name Size Bytes Class Attributes
B1 3x3 72 double
B2 3x3 646 cell
Pivot allows you to keep the headers or to strip them, and to specify any other placeholder instead of NaN for missing data. I recommend to use NaN and to keep the matrix as double and not a cell.
Oleg