I have a vector vv
containing market volume data for each tick, and a vector minuteIdx
containing an index for different minutes. I'm using accumarray
to sum the volume within each minute, like this:
orgMinuteVolumes = accumarray(minuteIdx, vv); %default function is @sum
notrades = orgMinuteVolumes == 0;
minuteVolumes = orgMinuteVolumes;
minuteVolumes(notrades) = [];
Usually it works perfectly, but occasionally volume data could not be obtained for all the ticks in a minute, and there are 0
s in the volume vector. This results in the minuteVolumes
vector being shorter than it would be otherwise since I got rid of all the zeros. For example if vv
begins with a 1
(and there is only one tick in the first minute), then minuteVolumes is 175
long, but if I change vv
to begin with a 0
then minuteVolumes
is only 174
long. I want a 0
to appear in my minuteVolumes
vector, not to make it shorter. Is there a smart way to make this happen? My original logic was that for a trade to occur volume had to be nonzero, but I didn't take into account occasional bad data.