MATLAB: How to code this? Resampling of vector

samplingvector

Hi all,
Currently I am trying to resample a signal by changing its signal frequency; The signal is given by time vector t and signal vector s. Example:
t=[ 1 2 3 4 5 6 7 8 9 10 11 12]
s=[3 3.5 3 5.5 2 2.5 3 5 7 2.5 3.5 4 ]
I want to create a vector s_new in which the sum of the values of s on the interval <0,4] is one element, the sum of interval <4,8] is an element etc, creating:
s_new= [15 12.5 17]
I have been toying around with histc but didnt succeed. Any ideas on coding this?
Thanks in advance! Lucas

Best Answer

For these straightforward time values, this will do
sum(reshape(s,4,3))
If t gets more complex you should be able to find a similar solution, though.
Related Question