[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vectorization
From: |
Bård Skaflestad |
Subject: |
Re: Vectorization |
Date: |
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
NUMEL(UNIQUE(pvals))-by-NUMEL(encoder)
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));
Sincerely,
--
Bård Skaflestad <address@hidden>
SINTEF ICT, Applied Mathematics