# How to reduce data irregularly?

10 vues (au cours des 30 derniers jours)
Mohamed Ibrahim le 17 Sep 2021
Réponse apportée : Jan le 20 Sep 2021
Hi All,
I have a plot consists of 10000 points that I need to reduce to upload it on an instrument which accepts only 200 points. The plot consists of three parts: first a straight line, a curve and again a straight line. I want to reduce the number of points like getting a small number of points for both lines and get more points for the curve. How can I do that?
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Image Analyst le 18 Sep 2021
Can you attach your data in a .mat file with the paperclip icon?

Connectez-vous pour commenter.

### Réponses (3)

Star Strider le 17 Sep 2021
One approach would be to use the gradient function to calculate the derivative of the available data. This will be greater than 1 (or different from a constant, depending on what the striaght lines are). Then randomly select points from the identified curve, and most likely adjacent points on the line (for example the last 5 before the curve begins and the first 5 after itt is defined to end). (These would be sorted by their independent variable values so the independent variable values are increasing.)
The gradient function is preferable to diff because the output is the same size as the input, making indexing easier.
.
##### 2 commentairesAfficher AucuneMasquer Aucune
Mohamed Ibrahim le 17 Sep 2021
Thanks for your reply but I have some questions. To clarify more the situation, my plot is shown here
so the imported data is stored in two vectors VarName 1 and VarName2. I should use gradient with the following command: gradient(VarName1, VarName2) right?
If it is so, I got the following plot:
Then I will start to choose 5 points before the curve and after the curve? how will they still be reduced?
Star Strider le 18 Sep 2021
This is not the sort of plot I expected to see.
I have no idea how to deal with that, other than to use:
idx = fix(linspace(1, 1E+4, 200));
idx = 1×200
1 51 101 151 201 252 302 352 402 453 503 553 603 654 704 754 804 855 905 955 1005 1056 1106 1156 1206 1257 1307 1357 1407 1458
and use ‘idx’ as the indices into both vectors. Those data (not supplied so I have no idea what they actually are) appparently have no specific statistical characteristics in the approximations I made to them that could be used for any sort of selective sampling.
.

Connectez-vous pour commenter.

Kelly Kearney le 17 Sep 2021
It sounds like you're looking for a line simplification algorithm. These algorithms try to preserve the shape of a polygon or polyline while reducing the number of points used. The Mapping Toolbox includes a version of the Douglas-Peucker method (reducem), and it looks like there are some FEX options (maybe this one?) available as well if you don't have that toolbox.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Jan le 20 Sep 2021
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Bartlett dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by