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 8613455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:52:47+00:00 2026-06-12T04:52:47+00:00

I have a vector which is normalize(i.e. the sum of its elements is 1

  • 0

I have a vector which is normalize(i.e. the sum of its elements is 1) and they are ordered descending(i.e. [0.5 0.4 0.09 0.01]).

Is there a way of obtaining the indices of the first elements who’s sum is just bellow a certain threshold?

For example, in my case, for a threshold of 0.6 I would obtain 1, the index(w.r.t. to Matlab way of indexing vector elements) of 0.5. For a threshold of 0.91 I would obtain [1 2], the indices of [0.5 0.4], and so on.

I know that I can do this with a loop through the vector but given the fact that I am using Matlab, I thought asking whether I can do this with just a single command line or max 2, thus increasing the computational speed of my code.

  • 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-12T04:52:49+00:00Added an answer on June 12, 2026 at 4:52 am

    The cumsum function computes the cumulative sum of a vector’s elements. doing this, and then finding the index for which the threshold turns smaller than the cumulative sum will give you your answer:

    V = [0.5 0.4 0.09 0.01]
    
    t = 0.6;
    
    index = find(t < cumsum(V), 1)-1
    

    Note that if index = 0, the condition does not hold even for the first element.

    If you insist on getting a vector of elements that qualify, you can simply define a range with this:

    indices = 1 : (find(t<cumsum(V),1)-1)
    

    In this case, the indices vector is empty in case the first element doesn’t qualify.

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

Sidebar

Related Questions

Say I have a vector which has thousands of elements. What is the R
I have a vector of strings which are changing its contents for no apparent
Lets say if I have a vector V, which has 10 elements. If I
First I want to say that, I have a vector which has thousand of
I have 2 tables Vector and VectorElement. A vector has many elements so there
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have a vector of pairs representing hops between nodes which I would like
Hey, In C++, I have a vector of type: vector<BaseClass*> myVector; In which, I
I have a numeric vector in R, which consists of both negative and positive
I have a class which has a private attribute vector rectVec; class A {

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.