gathering together specific elements from a column vector

1 回表示 (過去 30 日間)
antonet
antonet 2012 年 5 月 26 日
HI all, I have the matrix
A=
identif pairs time allpairs
[1] 'PDL12' 'JF2008' [ NaN]
[1] 'PDL12' 'JF2009' [-1.0000e-004]
[1] 'PDL12' 'MA2009' [ -0.0330]
[1] 'PDL12' 'MJ2009' [ -0.0268]
[1] 'PDL12' 'JA2009' [ -0.0264]
[1] 'PDL12' 'SO2009' [ -0.1913]
[1] 'PDL12' 'ND2009' [ -0.0415]
[1] 'PDL12' 'JF2010' [ -0.0168]
[1] 'PDL12' 'MA2010' [ -0.0502]
[1] 'PDL12' 'MJ2010' [ -0.0761]
[1] 'PDL12' 'JA2010' [ -0.0429]
[1] 'PDL12' 'SO2010' [ -0.0548]
[1] 'PDL12' 'ND2010' [ -0.0173]
[1] 'PDL12' 'JF2011' [ 0.0071]
[1] 'PDL12' 'MA2011' [ 0.0121]
[1] 'PDL12' 'MJ2011' [ -0.0727]
[1] 'PDL12' 'JA2011' [ -0.1628]
[1] 'PDL12' 'SO2011' [ 0.0056]
[2] 'PDL13' 'JF2008' [ NaN]
[2] 'PDL13' 'JF2009' [ 0.0218]
[2] 'PDL13' 'MA2009' [ -0.0037]
[2] 'PDL13' 'MJ2009' [ 0.0120]
[2] 'PDL13' 'JA2009' [ -0.0027]
[2] 'PDL13' 'SO2009' [-5.0000e-004]
[2] 'PDL13' 'ND2009' [ -0.2818]
[2] 'PDL13' 'JF2010' [ -0.0216]
[2] 'PDL13' 'MA2010' [ -0.0330]
[2] 'PDL13' 'MJ2010' [ -0.0468]
[2] 'PDL13' 'JA2010' [ -0.1309]
[2] 'PDL13' 'SO2010' [ -0.0318]
[2] 'PDL13' 'ND2010' [ -0.0014]
[2] 'PDL13' 'JF2011' [ -0.0779]
[2] 'PDL13' 'MA2011' [ 0.0224]
[2] 'PDL13' 'MJ2011' [ -0.0662]
[2] 'PDL13' 'JA2011' [ -0.2187]
[2] 'PDL13' 'SO2011' [ -0.0745]
and I want to group all the observations that correspond to JF2008 (JF=January and February) as follows
1 PDL12 JF2008
2 'PDL13' 'JF2008' [ NaN]
then all the observations that correspond to the next months
[1] 'PDL12' 'MA2008' [ -0.0330]
[2] 'PDL13' 'MA2008' [ 0.0218]
and so forth... . And then for the year 2009 similarly to 2008
thanks in advance
  2 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 5 月 26 日
Do you want to sort the table according to the third and then second row?
antonet
antonet 2012 年 5 月 26 日
adrei bobrov gave the solution. thank you as well

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 26 日
eg
k = cellstr(reshape(datestr(datenum(0,1:12,1,0,0,0),'m'),2,[])')
t = cellfun(@(x){x(1:2) x(3:end)},A(:,3),'un',0)
tt = cat(1,t{:})
[a,a] = ismember(tt(:,1),k)
[id,id] = sortrows([a,str2double(tt(:,2))],[2,1])
out = A(id,:)
OR
in this is case
out = A(reshape(reshape(1:size(A,1),[],2)',[],1),:)
  5 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 5 月 27 日
Say the matrix you posted is called A:
[trash idx] = sortrows([cat(1,A{:,1}) datenum(A(:,3),'mmm yyyy')],[2 1]);
A(idx,:)
antonet
antonet 2012 年 5 月 27 日
Thank you oleg. it works!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by