[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Wed, 8 Oct 2014 10:40:38 +0200
On Tue, 2014-10-07 at 21:12 -0700, Thomas D. Dean wrote:
> I have data collected from an optical encoder attached to a DC motor.
> The motor is driver with a PWM signal.
> PWM = [0:20:240 255 240: -20:-240 -255 -240:20:0]
> > size(encoder)
> 20571 1
> I want mean(encoder(PWM==20)) for each of the PWM values.
Here's one *possible* option. I'm not going to claim it's particularly
good because it generates an intermediate DOUBLE matrix of size
so you may want to look into a solution based on ACCUMARRAY or SPARSE
instead--especially if memory is tight.
[up, iu, iu] = unique(pvals(:));
v = double(up == reshape(pvals, 1, )) ...
* [ encoder(:), ones([numel(encoder), 1]) ];
L = v(:,1) ./ v(:,2);
L = reshape(L(iu), size(pvals));
Bård Skaflestad <address@hidden>
SINTEF ICT, Applied Mathematics