Home > Archive > Matlab > March 2007 > Different numbers in a vector
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Different numbers in a vector
|
|
| joseph 2007-03-30, 10:09 pm |
| Hi I have a long vector (600,000 observations) and i would like to
increase the effeciency of my codes. Is there a way to identify the
rows where I a number in this vector changes without using a loop.
For example:
[1;1;1;1;2;2;3;3;3;3;4;4;4]
is their a way to obtain an answer 5,7,11 which are the row where the
number changes without using a loop ?
| |
| John D'Errico 2007-03-30, 10:09 pm |
| joseph wrote:
>
>
> Hi I have a long vector (600,000 observations) and i would like to
> increase the effeciency of my codes. Is there a way to identify the
> rows where I a number in this vector changes without using a loop.
> For example:
>
> [1;1;1;1;2;2;3;3;3;3;4;4;4]
>
> is their a way to obtain an answer 5,7,11 which are the row where
> the
> number changes without using a loop ?
The idea is to think about what you
want to find. You have constant
subsequences, and you want to find
where they change.
So suppose you used diff on this
vector?
Now, what would find do on the result?
HTH,
John
|
|
|
|
|