arrays

조회 수: 1 (최근 30일)
Tiina
Tiina 2012년 2월 9일
편집: Cedric 2013년 10월 19일
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.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 2월 9일
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
Andrei Bobrov
Andrei Bobrov 2012년 3월 2일
p = datenum(cellfun(@str2num,mat2cell(num2str(M(:,1:2)*[10^6;1]),ones(size(M,1),1),[4 2 2 2 2 2])))
Tiina
Tiina 2012년 3월 3일
yes this works on the example here, little issue remaining in the real data, the accumarray is returning an error "first input SUBs must be zero ..." this is perhaps caused by the histc which produces some zeros in the real data , is there a fix around that .. I am voting for you once now althoughu deserve more thanks for your patience

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by