"Michael Hosea" <mhosea@mathworks.com> wrote in message
<ffji8d$42h$1@fred.mathworks.com>...
> Mark,
>
> You basically have to work around the fixedsize
restriction.
> Unfortunately, that's going to limit some of the things
you can do with the
> library functions, but you can make things work with your
own functions.
> One way is to use a fixed size output and also return the
number of "active"
> elements. Here's an example.
>
> function y = foo(x) %#eml
> % Calculate the average of elements greater than 0.5.
> [idx,n] = myfind(x>0.5);
> % Note that we can't use MEAN or SUM on x(idx).
> y = 0;
> for k = 1:n
> y = y + x(idx(k));
> end
> if n > 0
> y = y / double(n);
> end
>
> function [idx,n] = myfind(b)
> % FINDlike function.
> % Input B is a logical array.
> % Output IDX is a column vector with numel(b) elements.
> % Output N is the number of elements of IDX in use.
> n = uint32(0);
> idx = zeros(numel(b),1,'uint32');
> for k = 1:numel(b)
> if b(k)
> n = n + 1;
> idx(n) = k;
> end
> end
>
> I've taken the liberty here to make the idx
vector 'int32' instead of
> double.
> 
> Mike
>
> "Mark " <medwar19.nospam@hotmail.com> wrote in message
> news:ffjetb$en7$1@fred.mathworks.com...
> > Hi experts,
> >
> > Does anyone know how to implement a 'find' alternative
in
> > Embedded Matlab.
> >
> > I have a lot of large arrays in Stateflow and want to
> > filter and sort them for a range of criteria.
> >
> > I need the indices from the searches to get back to the
> > original data, hence:
> >
> > find(A == 20)
> >
> > would give me the indices that I can then use to index
into
> > other arrays.
> >
> > Any thoughts greatley appreciated.
> >
> >
> > Mark.
>
>
Hi Michael,
That's exactly what I needed, thanks!
