Suming data over 10 sec period
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi
I'm trying to sum my findings over 10 sec period of time. My test data is:
C = [2 3 5 1 0 9 8 7 3 0 2 3 8 0 8]; %data
t = [0.04 1 3 6.4 10 12 19.9 22 26.2 28 30 33.3 35 37 40]; %time
Meaning that my new_C would be:
new_C = [11 17 12 19];
Could you please help me?
0 comentarios
Respuestas (3)
Azzi Abdelmalek
el 28 de Sept. de 2013
Editada: Azzi Abdelmalek
el 28 de Sept. de 2013
C = [2 3 5 1 0 9 8 7 3 0 2 3 8 0 8]; %data
t = [0.04 1 3 6.4 10 12 19.9 22 26.2 28 30 33.3 35 37 39]; %time
id=[0 10:10:ceil(max(t)/10)*10]
out=arrayfun(@(x) sum(C(t>id(x)& t<=id(x+1))),1:numel(id)-1)
0 comentarios
Image Analyst
el 28 de Sept. de 2013
Here's one intuitive, easy to understand, easy to follow way that works:
C = [2 3 5 1 0 9 8 7 3 0 2 3 8 0 8]; %data
t = [0.04 1 3 6.4 10 12 19.9 22 26.2 28 30 33.3 35 37 40];
% Find indexes where we are at a multiple of 10
for k = 1 : length(t)
edges(k) = find(t <= 10*k, 1, 'last');
end
indexes = [0, unique(edges)]
% Sum C up in the intervals.
for k = 2:length(indexes)
theSumOfC(k-1) = sum(C((indexes(k-1)+1):indexes(k)));
end
% Print to command line
theSumOfC
though if you wait long enough, someone will come up with a compact cryptic one-liner.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!