From: Oleg Komarov on
"Ignazio G" <igiuntoli(a)yahoo.it> wrote in message <i14it2$icu$1(a)fred.mathworks.com>...
> Thank you very much, that's exactly what I wanted to do!
> My last question: is there a way to get the date back from datenum format
> to 'year month day'?

substitute:
Out = [unDates zeros(numel(unDates),1)];

with :
Out = [In(:,1:3) zeros(numel(unDates),1)];

Oleg
From: Oleg Komarov on
Also:
Out(d,2) = mean(In(IDX == d,end));

Out(d,end) = ...

Oleg
From: Ignazio G on
> substitute:
> Out = [unDates zeros(numel(unDates),1)];
>
> with :
> Out = [In(:,1:3) zeros(numel(unDates),1)];


I did substitute as you suggested, but I got this error:

>??? Error using ==> horzcat
>All matrices on a row in the bracketed expression must have the
>same number of rows.
>
>Error in ==> C:\MATLAB6p5\work\proc Guyane\bonne_qjmoyenne.m
>On line 22 ==> Out = [In(:,1:3) zeros(numel(unDates),1)];
From: Oleg Komarov on
> I did substitute as you suggested, but I got this error:
>
> >??? Error using ==> horzcat
> >All matrices on a row in the bracketed expression must have the
> >same number of rows.
> >
> >Error in ==> C:\MATLAB6p5\work\proc Guyane\bonne_qjmoyenne.m
> >On line 22 ==> Out = [In(:,1:3) zeros(numel(unDates),1)];

Sorry, I gave the wrong solution; forget it and use this one:

In = [1968 11 13 139.5
1968 11 13 139.5
1968 11 13 138.4
1968 11 13 138.6
1968 11 14 131.4
1968 11 14 129.8
1968 11 15 132.1
1968 11 15 131
1968 11 15 131 ];

% Unique dates and index
[unDates,trash,IDX] = unique(In(:,1:3),'rows'); % Do you have the 'rows' option?; can't find when it was added

%Preallocate output
Out = [unDates zeros(size(unDates,1),1)];
% Averaging
for d = 1:size(unDates,1)
Out(d,end) = mean(In(IDX == d,end));
end

Oleg
From: Ignazio G on
Thanks a lot, it does work with 'rows' option under Matlab 6 !
happy to do it without having to transform date back and forth !

> Sorry, I gave the wrong solution; forget it and use this one:
>
> In = [1968 11 13 139.5
> 1968 11 13 139.5
> 1968 11 13 138.4
> 1968 11 13 138.6
> 1968 11 14 131.4
> 1968 11 14 129.8
> 1968 11 15 132.1
> 1968 11 15 131
> 1968 11 15 131 ];
>
> % Unique dates and index
> [unDates,trash,IDX] = unique(In(:,1:3),'rows'); % Do you have the 'rows' option?; can't find when it was added
>
> %Preallocate output
> Out = [unDates zeros(size(unDates,1),1)];
> % Averaging
> for d = 1:size(unDates,1)
> Out(d,end) = mean(In(IDX == d,end));
> end
>
> Oleg