gathering together specific elements from a column vector

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Oleg Komarov
Oleg Komarov il 26 Mag 2012
Do you want to sort the table according to the third and then second row?
antonet
antonet il 26 Mag 2012
adrei bobrov gave the solution. thank you as well

Accedi per commentare.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 26 Mag 2012
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 Commenti
Oleg Komarov
Oleg Komarov il 27 Mag 2012
Say the matrix you posted is called A:
[trash idx] = sortrows([cat(1,A{:,1}) datenum(A(:,3),'mmm yyyy')],[2 1]);
A(idx,:)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by