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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:06:44+00:00 2026-05-11T01:06:44+00:00

The last question I asked concerned how to bin data by x co-ordinate. The

  • 0

The last question I asked concerned how to bin data by x co-ordinate. The solution was simple and elegant, and I’m ashamed I didn’t see it. This question may be harder (or I may just be blind).

I started out with about 140000 data points and split them into 70 groups equally spaced along the x axis I then took the average position (x_avg, y_avg) of each group and plotted them; a nice curve appeared. Unfortunately there are two problems. First of all, the edges are much less populated than the center of the graph; Second of all, some areas change more than others and thus need a better resolution.

I thus have two specific questions and a general invitation to throw suggestions:

Does matlab have a builtin way of splitting a matrix into either a fixed number of smaller matricies or smaller matricies of a fixed size?

Is there an algorithm (or a matlab function, but I find that unlikely) to determine the boundaries required to bin regions of interest more finely?

More generally, is there a better way of condensing tens of thousands of data points into a neat trend?

  • 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. 2026-05-11T01:06:44+00:00Added an answer on May 11, 2026 at 1:06 am

    It sounds like you want to use bins that vary in size depending on the density of x values. I think you can still use the function HISTC like in the answer to your previous post, but you would just have to give it a different set of edges.

    I don’t know if this is exactly want you want, but here’s one suggestion: instead of splitting the x axis into 70 equally spaced groups, split the sorted x data into 70 equal groups and determine the edge values. I think this code should work:

    % Start by assuming x and y are vectors of data:  nBins = 70; nValues = length(x); [xsort,index] = sort(x);  % Sort x in ascending order ysort = y(index);         % Sort y the same way as x binEdges = [xsort(1:ceil(nValues/nBins):nValues) xsort(nValues)+1];  % Bin the data and get the averages as in previous post (using ysort instead of y):  [h,whichBin] = histc(xsort,binEdges);  for i = 1:nBins     flagBinMembers = (whichBin == i);     binMembers = ysort(flagBinMembers);     binMean(i) = mean(binMembers); end 

    This should give you bins that vary in size with the data density.


    UPDATE: Another version…

    Here’s another idea I came up with after a few comments. With this code, you set a threshold (maxDelta) for the difference between neighboring data points in x. Any x values that differ from their larger neighbor by an amount greater than or equal to maxDelta are forced to be in their own bin (all by their lonesome). You still choose a value for nBins, but the final number of bins will be larger than this value when spread-out points are relegated to their own bins.

    % Start by assuming x and y are vectors of data:  maxDelta = 10; % Or whatever suits your data set! nBins = 70; nValues = length(x); [xsort,index] = sort(x);  % Sort x in ascending order ysort = y(index);         % Sort y the same way as x  % Create bin edges:  edgeIndex = false(1,nValues); edgeIndex(1:ceil(nValues/nBins):nValues) = true; edgeIndex = edgeIndex | ([0 diff(xsort)] >= maxDelta); nBins = sum(edgeIndex); binEdges = [xsort(edgeIndex) xsort(nValues)+1];  % Bin the data and get the y averages:  [h,whichBin] = histc(xsort,binEdges);  for i = 1:nBins     flagBinMembers = (whichBin == i);     binMembers = ysort(flagBinMembers);     binMean(i) = mean(binMembers); end 

    I tested this on a few small sample sets of data and it seems to do what it’s supposed to. Hopefully it will work for your data set too, whatever it contains! =)

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

Sidebar

Related Questions

This is similar to this question I asked last week. My dataGrid is populated
I guess this is a continuation of the last question I asked: bulk insert
So I've seen this question asked before and in fact I asked it last
I was asked a question in C last night and I did not know
Since I didn't do a good job writing the last question, and most of
I didn't give a lot of info in my last question. I've built llv8call
last time I asked how to populate a data structure here . Now I
This question is about the same program I previously asked about . To recap,
I have seen this question asked in a couple of different ways on SO
In my last question I asked how to best send a string from one

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.