grouping observations accordeing to string dates with empty cells

1 次查看(过去 30 天)
Dear all,
I have the following matrix
[1] 'PDL12' '' [ NaN]
[1] 'PDL12' 'JF 2009' [-1.0000e-004]
[1] 'PDL12' 'MA 2009' [ -0.0330]
[1] 'PDL12' 'MJ 2009' [ -0.0268]
[1] 'PDL12' 'JA 2009' [ -0.0264]
[1] 'PDL12' 'SO 2009' [ -0.1913]
[1] 'PDL12' 'ND 2009' [ -0.0415]
[1] 'PDL12' 'JF 2010' [ -0.0168]
[1] 'PDL12' 'MA 2010' [ -0.0502]
[1] 'PDL12' 'MJ 2010' [ -0.0761]
[1] 'PDL12' 'JA 2010' [ -0.0429]
[1] 'PDL12' 'SO 2010' [ -0.0548]
[1] 'PDL12' 'ND 2010' [ -0.0173]
[1] 'PDL12' 'JF 2011' [ 0.0071]
[1] 'PDL12' 'MA 2011' [ 0.0121]
[1] 'PDL12' 'MJ 2011' [ -0.0727]
[1] 'PDL12' 'JA 2011' [ -0.1628]
[1] 'PDL12' 'SO 2011' [ 0.0056]
[2] 'PDL13' '' [ NaN]
[2] 'PDL13' 'JF 2009' [ 0.0218]
[2] 'PDL13' 'MA 2009' [ -0.0037]
[2] 'PDL13' 'MJ 2009' [ 0.0120]
[2] 'PDL13' 'JA 2009' [ -0.0027]
[2] 'PDL13' 'SO 2009' [-5.0000e-004]
[2] 'PDL13' 'ND 2009' [ -0.2818]
[2] 'PDL13' 'JF 2010' [ -0.0216]
[2] 'PDL13' 'MA 2010' [ -0.0330]
[2] 'PDL13' 'MJ 2010' [ -0.0468]
[2] 'PDL13' 'JA 2010' [ -0.1309]
[2] 'PDL13' 'SO 2010' [ -0.0318]
[2] 'PDL13' 'ND 2010' [ -0.0014]
[2] 'PDL13' 'JF 2011' [ -0.0779]
[2] 'PDL13' 'MA 2011' [ 0.0224]
[2] 'PDL13' 'MJ 2011' [ -0.0662]
[2] 'PDL13' 'JA 2011' [ -0.2187]
[2] 'PDL13' 'SO 2011' [ -0.0745]
[3] 'PDL14' '' [ NaN]
[3] 'PDL14' 'JF 2009' [ -0.0107]
As you can see the date before JF2009 is empty. I would like to group all the observations that correspond to the empty cell, then all the observations that correspond to JF2009, then all the observations that correspond to MA2009 and similarly for the years 2011 and 2011
thanks

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-28
try
ms = cellstr(reshape(datestr(datenum(0,1:12,1,0,0,0),'m'),2,[])');
dd = regexprep(data(:,3),ms,cellstr(('1':num2str(numel(ms)))'));
dd(cellfun('isempty',dd)) = {'0 0000'};
[id,id] = sort(datenum(dd,'mm yyyy'));
out = data(id,:);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 PID Controller Tuning 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by