data frequency conversion -cell matrix

1 view (last 30 days)
Dear all,
I have the following cell matrix
A = {
1 ' ' [ NaN] [ NaN]
1 ' ' [ NaN] [ NaN]
1 ' ' [ NaN] [ NaN]
1 'MA 2009' [ 0] [ 0]
1 'MJ 2009' [ 0.2680] [ 3.0394]
1 'JA 2009' [ 0.0504] [ 0.6475]
1 'SO 2009' [ 14.0985] [ 148.2583]
1 'ND 2009' [ 0.1128] [ 1.1506]
1 'JF 2010' [ NaN] [ 148.2583]
1 'MA 2010' [ 2.5852] [ 34.0146]
1 'MJ 2010' [ 0.3220] [ 3.2846]
1 'JA 2010' [ 14.0985] [ 148.2583]
1 'SO 2010' [ 2.5852] [ NaN]
1 'ND 2010' [ 0.2938] [ 2.8540]
1 'JF 2011' [ 0.1128] [ 1.1506]
1 'MA 2011' [ 14.0985] [ 148.2583]
1 'MJ 2011' [ 2.1091] [ 15.0233]
1 'JA 2011' [ 0] [ 0]
2 ' ' [ NaN] [ NaN]
2 ' ' [ NaN] [ NaN]
2 ' ' [ NaN] [ NaN]
2 'MA 2009' [ 14.0985] [ 148.2583]
2 'MJ 2009' [ 2.7827] [ 18.9879]
2 'JA 2009' [ 11.8755] [ 126.4359]
2 'SO 2009' [ 0.0589] [ 0.6685]
2 'ND 2009' [ 11.8755] [ 126.4359]
2 'JF 2010' [ 0.0504] [ 0.6475]
2 'MA 2010' [ 11.8755] [ 126.4359]
2 'MJ 2010' [ 0.0504] [ 0.6475]
2 'JA 2010' [ 0] [ 0]
2 'SO 2010' [ 0.0248] [ 0.2823]
2 'ND 2010' [ 0] [ 0]
2 'JF 2011' [ 2.5852] [ 34.0146]
2 'MA 2011' [ 0.0207] [ 0.2282]
2 'MJ 2011' [ 11.8755] [ 126.4359]
2 'JA 2011' [ 14.0985] [ 148.2583]
3 ' ' [ NaN] [ NaN]
3 ' ' [ NaN] [ NaN]
3 ' ' [ NaN] [ NaN]
3 'MA 2009' [ 2.1091] [ 15.0233]
3 'MJ 2009' [ 0] [ 0]
3 'JA 2009' [ 0.1128] [ 1.1506]
3 'SO 2009' [ 0.0207] [ 0.2282]
3 'ND 2009' [ 0] [ 0]
3 'JF 2010' [ NaN] [ 1.1506]
3 'MA 2010' [ 0] [ 0]
3 'MJ 2010' [ 2.1091] [ 15.0233]
3 'JA 2010' [ 0] [ 0]
3 'SO 2010' [ 2.7827] [ NaN]
3 'ND 2010' [ 0] [ 0]
3 'JF 2011' [ 0.0207] [ 0.2282]
3 'MA 2011' [ 2.5852] [ 34.0146]
3 'MJ 2011' [ 0] [ 0]
3 'JA 2011' [ 11.8755] [ 126.4359]
}
I want to convert these data from Bimontly to monthly for each inividual i (first column).
I searched for relevant functions and I found for example: tomonthly() but I do not know how to exactly apply it to the above setting. Note that I have 30000 invividuals and 20 numerical columns instead of the last 2 that I display above
Any help is greately appreicated thanks in advance
  9 Comments
salva
salva on 27 Jul 2012
yes exactly I want to start with A and obtain Aout. Please helppppp!
thanks
Oleg Komarov
Oleg Komarov on 27 Jul 2012
@Andrei: he wants to divide it by 2.

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 28 Jul 2012
n = cellfun(@(x)x/2,A(:,3:end),'un',0);
Out = [];
for ii = 1:size(A,1)
if strcmp(A(ii,2),' ')
Out = [Out; A(ii,:)];
else
[~,k] = ismember(A{ii,2}(1:2),{'JF','MA','MJ','JA','SO','ND'});
y = A{ii,2}(4:end);
Out = [Out;
[A(ii,1),{[sprintf('%d',k*2-1),'/',y]},n(ii,:);
A(ii,1),{[sprintf('%d',k*2),'/',y]},n(ii,:)]];
end
end

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!