From: Richard on
I have a vector of integer elements. I want to search it for specific values, say x, that occur more than once within the vector. e.g. vector might be a 400 element vector with the following 14 rows somewhere in it

234
222
12
56
87
54
54
322
302
108
108
108
219
219

whats the quickest way to return the indexes of all occurrences of 108 as I want to delete those rows?
Thanks!
From: us on
"Richard " <REMOVETHISrcaldwellie(a)yahoo.com> wrote in message <i3mm65$8q1$1(a)fred.mathworks.com>...
> I have a vector of integer elements. I want to search it for specific values, say x, that occur more than once within the vector. e.g. vector might be a 400 element vector with the following 14 rows somewhere in it
>
> 234
> 222
> 12
> 56
> 87
> 54
> 54
> 322
> 302
> 108
> 108
> 108
> 219
> 219
>
> whats the quickest way to return the indexes of all occurrences of 108 as I want to delete those rows?
> Thanks!

one of the many solutions
- assume V is your col vec...

v(v==108)=[];

us
From: dpb on
Richard wrote:
> I have a vector of integer elements. I want to search it for specific
> values, say x, that occur more than once within the vector. e.g. vector
> might be a 400 element vector with the following 14 rows somewhere in it
>
> 234 222 12 56 87 54 54 322 302 108 108 108 219 219
>
> whats the quickest way to return the indexes of all occurrences of 108
> as I want to delete those rows?

What's the criterion for deciding what the value is to be deleted?

[n,b]=histc(x,unique(x));

may prove of interest.

And, of course,

x(x==108)=[]; % once you've determined "how" the 108 is TBD

--
From: Richard on
dpb <none(a)non.net> wrote in message <i3mn42$j3u$1(a)news.eternal-september.org>...
> Richard wrote:
> > I have a vector of integer elements. I want to search it for specific
> > values, say x, that occur more than once within the vector. e.g. vector
> > might be a 400 element vector with the following 14 rows somewhere in it
> >
> > 234 222 12 56 87 54 54 322 302 108 108 108 219 219
> >
> > whats the quickest way to return the indexes of all occurrences of 108
> > as I want to delete those rows?
>
> What's the criterion for deciding what the value is to be deleted?
>
> [n,b]=histc(x,unique(x));
>
> may prove of interest.
>
> And, of course,
>
> x(x==108)=[]; % once you've determined "how" the 108 is TBD
>
> --
thanks us and dpb.
dpb, the value is a communications node identifier. criteria for deletion is that its causing too much interference and is decided elswhere in code. Looks like
x(x==108)=[]; is most suitable.
trying to speed up my code as its running way too slow. hard to believe how badly its written in terms of execution time as I learn more matlab!!! I've been iterating through a vector of 400 items making a log of matches and then using x=[];
From: dpb on
Richard wrote:
....

> trying to speed up my code as its running way too slow. hard to believe
> how badly its written in terms of execution time as I learn more
> matlab!!! I've been iterating through a vector of 400 items making a log
> of matches and then using x=[];

Then unique() and/or histc() should be useful in eliminating the loop
and logging.

As for speedups, other than the obvious looking for things that can be
vectorized but aren't,

doc profile

before spending much time a priori "optimizing" to ensure you're
actually working on the bottlenecks.

--