From: Hans on
"Hans " <jyde_6(a)msn.com> wrote in message <hhfgfm$93o$1(a)fred.mathworks.com>...
> "us " <us(a)neurol.unizh.ch> wrote in message <hhffp7$ot9$1(a)fred.mathworks.com>...
> > "Hans " <jyde_6(a)msn.com> wrote in message <hhfenf$j31$1(a)fred.mathworks.com>...
> > > Hi everybody
> > >
> > > Under I have copied the code for the function searchvec that search through a vector vec to find the value key.
> > > As an example vec=[15 10 7 8 98 8 3 8] and key=8. The function returns [4 6 8]. What I want is that key should be a vector instead of a scalar. As example vec=[15 10 7 8 98 8 3 8] and key=[15 8]. The function should return [1 4 6 8]. How can I change the function file. It must be a function.
> >
> > one of the many solutions
> >
> > v=[2,3,15,8,8,0,1,15];
> > k=[8,15];
> > r=find(ismember(v,k))
> > % r = 3 4 5 8
> >
> > us
>
>
> Thank you very much US. I will try the ismember and use the tic toc to see what is fastest.
>
> Best Regards
>
> Hans

Dear John and US.

What if it was a cellarray it has to search through and find some values?How would the code looklike?

Best Regards

Hans
From: us on
"Hans "
> Dear John and US.
>
> What if it was a cellarray it has to search through and find some values?How would the code looklike?
>
> Best Regards
>
> Hans

one of the solutions

v=num2cell([2,3,15,8,8,0,1,15]); % a CELL
k=[8,15];
r=find(ismember([v{:}],k))
% r = same result as above...

us
First  |  Prev  | 
Pages: 1 2
Prev: diameter
Next: contrability in state space system