MATLAB Answers

How can I group data points together

5 views (last 30 days)
Matthew Suddith
Matthew Suddith on 30 Nov 2020
Commented: Matthew Suddith on 2 Dec 2020
This question was flagged by Image Analyst

  3 Comments

Rik
Rik on 2 Dec 2020
I don't seem to be able to make a capture of the cache, but here is the content anyway:
I need to "bin" data points together into one number. This file has 70,000 lines of data points, in unevenly spaced, often repeating increments. For example, I need to average all the different numbers (2.419, 2.417, 2.405, etc...) with decimals into 2.000.
Matthew Suddith
Matthew Suddith on 2 Dec 2020
Thank you! I meant to edit it but I completely deleted it and couldnt figure out how to get it back.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 30 Nov 2020
It doesn't sound like you want to average them. For the example you've given, why not just round the numbers down to 2? The functions round, ceil, floor and fix might be of interest to you.
vals = [2.419, 2.417, 2.405];
round(vals)
ans = 1×3
2 2 2
ceil(vals)
ans = 1×3
3 3 3
floor(vals)
ans = 1×3
2 2 2
fix(vals)
ans = 1×3
2 2 2

  35 Comments

Cris LaPierre
Cris LaPierre on 1 Dec 2020
It looks like by default it writes a csv file. You could look at the name-value pairs for what options are available.
For more control, fprintf may be what you need.
Matthew Suddith
Matthew Suddith on 2 Dec 2020
That worked. How could I plot my rounded data and the original data in one plot for a direct comparison, is that doable?

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!