Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:36:55+00:00 2026-06-07T16:36:55+00:00

I am trying to identify if a value is repeated sequentially in a vector

  • 0

I am trying to identify if a value is repeated sequentially in a vector N times. The challenge I am facing is that it could be repeated sequentially N times several times within the vector. The purpose is to determine how many times in a row certain values fall above the mean value. For example:

>> return_deltas

return_deltas = 

      7.49828129642663
      11.5098198572327
      15.1776644881294
       11.256677995536
      6.22315734182976
      8.75582103474613
      21.0488849115947
       26.132605745393
      27.0507649089989
      ...

(I only printed a few values for example but the vector is large.)

>> mean(return_deltas)

ans =

     10.50007490258002

>> sum(return_deltas > mean(return_deltas))

ans =

    50

So there are 50 instances of a value in return_deltas being greater than the mean of return_deltas.

I need to identify the number of times, sequentially, the value in return_deltas is greater than its mean 3 times in a row. In other words, if the values in return_deltas are greater than its mean 3 times in a row, that is one instance.

For example:

---------------------------------------------------------------------
| `return_delta` value | mean        | greater or less | sequence   |
|--------------------------------------------------------------------
|   7.49828129642663   |10.500074902 | LT              | 1          |
|  11.5098198572327    |10.500074902 | GT              | 1          |
|  15.1776644881294    |10.500074902 | GT              | 2          |
|   11.256677995536    |10.500074902 | GT              | 3 *        |
|  6.22315734182976    |10.500074902 | LT              | 1          |
|  8.75582103474613    |10.500074902 | LT              | 2          |
|  21.0488849115947    |10.500074902 | GT              | 1          |
|   26.132605745393    |10.500074902 | GT              | 2          |
|  27.0507649089989    |10.500074902 | GT              | 3 *        |
---------------------------------------------------------------------

The star represents a successful sequence of 3 in a row. The result of this set would be two because there were two occasions where the value was greater than the mean 3 times in a row.

What I am thinking is to create a new vector:

>> a = return_deltas > mean(return_deltas)

that of course contains ones where values in return_deltas is greater than the mean and using it to find how many times sequentially, the value in return_deltas is greater than its mean 3 times in a row. I am attempting to do this with a built in function (if there is one, I have not discovered it) or at least avoiding loops.

Any thoughts on how I might approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:36:57+00:00Added an answer on June 7, 2026 at 4:36 pm

    With a little work, this snippet finds the starting index of every run of numbers:

    [0 find(diff(v) ~= 0)] + 1
    

    An Example:

    >> v = [3 3 3 4 4 4 1 2 9 9 9 9 9];           # vector of integers
    >> run_starts = [0 find(diff(v) ~= 0)] + 1    # may be better to diff(v) < EPSILON, for floating-point
    
    run_starts =
    
         1     4     7     8     9
    

    To find the length of each run

    >> run_lengths = [diff(run_starts), length(v) - run_starts(end) + 1]
    

    This variables then makes it easy to query which runs were above a certain number

    >> find(run_lengths >= 4)
    
    ans =
    
         5
    
    >> find(run_lengths >= 2)
    
    ans =
    
         1     2     5
    

    This tells us that the only run of at least four integers in a row was run #5.
    However, there were three runs that were at least two integers in a row, specifically runs #1, #2, and #5.
    You can reference where each run starts from the run_starts variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to identify all the nodes in a tree that lead to
I am trying to identify SQL INSERTS that occur when a record is viewed
I'm trying to use Jquery to firstly identify specific words within a span tag,
I am trying to update a table by passing value within the query. Note
I am trying to build a table that summarizes how many times pages in
I'm trying to identify if this is an IIS issue or a code issue.
I am trying to identify when an action without authorization has been made. Is
I am trying to identify a screen in a multi-monitor setup to save some
I am trying to identify duplicate serial numbers from the following xml using XPath
I am trying to identify file types for directory entries (Windows Unix etc..). In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.