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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:34:38+00:00 2026-06-02T12:34:38+00:00

Lets say we have following vector: data=a=[2.3 3.2 4.1 6.2 7.3 6.4 5.5 4.3

  • 0

Lets say we have following vector:

data=a=[2.3 3.2 4.1 6.2 7.3 6.4 5.5 4.3 3.2 2.6 1.7 3.4 4.5 5.7 6.8];

If we count the numbers only by using the hist-function, we get something like that:

[n xout]=hist(a,[1:1:max(a)])

n =

 0     0     2     4     3     1     3     2

xout =

 0     1     2     3     4     5     6     7

What i now want to make is to sum each element of a bin:

xout =

 0     1     2     3     4     5     6     7

n =

 0     0     2     4     3     1     3     2

binsum =

0      0     4    12.4 etc.

for the third bin for example i have n(3)=2 values that are between 1,5 and 2,5 (size of a bin):1.7 and 2.3 -> 1.7+2.3=4 -> binsum(3)=4
for the fourth bin i have n(4)=4 values that are between 2,5 and 3,5:3.2+3.2+3.4+2.6=12.4-> binsum(4)=12.4 etc.

is there a simple function which do this job?

  • 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-02T12:34:41+00:00Added an answer on June 2, 2026 at 12:34 pm

    If your histogram bins are defined by the array minBin:binWidth:maxBin, then you can find the indices of the bins, and then sum up the data like this:

    minBin = 1;
    binWidth = 1;
    maxBin = 7;
    
    data=[2.3 3.2 4.1 6.2 7.3 6.4 5.5 4.3 3.2 2.6 1.7 3.4 4.5 5.7 6.8];
    
    %# to create index: First, take care of out-of-range data points
    tmp = max(min( data, maxBin),minBin);
    %# then, subtract minimum, divide by step, round: this is the binIdx
    %# add 1 so that we don't start counting at 0
    idx = round( (tmp-minBin)/binWidth ) +1;
    
    %# now we can use accumarray to sum up the data
    binSum = accumarray(idx(:),data(:),[floor((maxBin-minBin)/binWidth)+1, 1], @sum, 0)
    
    binSum =
    
             0
        4.0000
       12.4000
        8.4000
        4.5000
       23.8000
       14.1000
    

    Note that I don’t get two zeros first, because I use the bins you used as input to hist, not the ones you apparently used to generate the outputs. Also, you can get the counts by replacing data by ones(length(data),1).

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

Sidebar

Related Questions

Lets say we have the following code: std::vector<int> f() { std::vector<int> y; ... return
Lets say for example I have the following 2 vectors: *B *A The vector
As a matter of interest, lets say I have the following class: class Data
Lets say i have vector of vectors vector< vector<int> > bigTable; vector<int> data; data.resize(2);
Lets say I have the following xml. <root> <data> <a>ATTITUDE_ANNOYED</a> <b>ATTITUDE_CAUTIOUS</b> <c>25</c> <d>30</d> </data>
Let's say I have following function: int foo (int a) { return something; }
Lets say we have following models. class User(db.Model): username=db.StringProperty() avatar=db.ReferenceProperty() class User(db.Model): username=db.StringProperty() avatar=db.StringProperty()
Lets say I have the following package Hierarchy: A--> B --> C --> D
Lets say I have the following: f (a, b) = if a == 0
Lets say I have the following script k <- as.numeric(readline(Start Index: )) tot <-

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.