arrays
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I ve got the following issue again with unequal arrays (unequal days and unequal time intervals within the days) and want to add units lets say every minute for every day over many different days, the issue is with keeping unreported times within the day to maintain equal time intervals
yyyymmdd hhmmss unit
20120103 93501 0
20120103 93503 0
20120103 93504 3500
20120103 93506 0
20120103 93507 0
20120103 93560 100
20120103 93600 0
20120103 93602 300
20120103 93603 0
20120103 93604 200
20120103 93659 0
20120103 93801 100
Output for every day for every minute during the day
20120103 93500 3600
20120103 93600 500
20120103 93700 0 (needed to keep equal time intervals)
20120103 93800 100
any suggestions will help.
0 comentarios
Respuestas (1)
Andrei Bobrov
el 9 de Feb. de 2012
M = dlmread('yourdata.txt');
M(:,2) = fix(M(:,2)*.01)*100;
m = 10^max(ceil(log10(M(:,2))));
k = M(:,1:2)*[m;1];
[a n n] = unique(k);
k1 = setdiff(min(k):100:max(k),k);
k2 = sortrows([a accumarray(n,M(:,3));k1 zeros(numel(k1),1)],1);
k3 = k2(:,1)/m;
out = [fix(k3) rem(k3,1)*m k2(:,2)]
ADD
using without keeping equal time intervals
M = dlmread('yourdata.txt');
m = 10^max(ceil(log10(M(:,2))));
M(:,2) = fix(M(:,2)*.01)*100;
k = M(:,1:2)*[m;1];
[a n n] = unique(k);
out = [fix(a/m) rem(a/m,1)*m accumarray(n,M(:,3))];
[ EDIT ] variant for untervals 5 min (on last comment Tiina)
M = dlmread('yourdata.txt');
m = 10^6;
k = M(:,1:2)*[m;1];
p = datenum(num2str(k),'yyyymmddHHMMSS');
p1 = datevec(p([1,end]));
n = 5;%interval - 5 minutes
p1(:,5) = p1(:,5) - mod(p1(:,5).*[1;-1],n).*[1;-1];
p1(:,end) = 0;
p2 = datenum(p1);
k2 = (p2(1):n/1440:p2(end)).';
[bin,bin] = histc(p,k2);
kout = datestr(k2,'yyyymmddHHMMSS')-'0';
k1c = [kout(:,1:8)*10.^(7:-1:0).' kout(:,9:end)*10.^(5:-1:0).'];
out = [k1c accumarray(bin,M(:,3),size(k2))];
19 comentarios
Andrei Bobrov
el 2 de Mzo. de 2012
p = datenum(cellfun(@str2num,mat2cell(num2str(M(:,1:2)*[10^6;1]),ones(size(M,1),1),[4 2 2 2 2 2])))
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!