How to Delete Every Other Similar Point in a Plot

6 次查看(过去 30 天)
Hello,
I'm trying to write a script that searches a sinusoidal type curve and removes similar points on that curve.
The sinusoidal type curve is not exactly repeating, but the same relative shape.
With that in mind, what I have now compares a row with the next row to a tolerance.
One problem with this is that the curves loses its shape, since I have the searching part of the script saving the point which each other data point is being compared to.
In other words, before I refine the curve, it will look like the Before.PNG image attached, and after I run my script it will look like the After.PNG image attached.
As you can see in the attached After.PNG image, the curve loses its overall shape.
Therefore, my next iteration on this script, instead of always deleting the second point (the point which is compared to the constant point), I would like to alternate between deleting the first and second point.
So it look something like it does in the Alternate.PNG image attached.
Originally my code looks something like this:
for J=1:Length
for I=1:Length
if I~=J
if "tolerance check goes here"
"Set each elemet in Ith row to -1"
end
end
So the J point is held constant as the I point changes, then I make the I point element to -1.
I later go on to delete all rows whose elements are all less than zero.
What I'm thinking I can do is have an if/else statement looking for if the I is positve or negative, then have it delete the Ith or Jth row depending on which one it is.
for J=1:Length
for I=1:Length
if I~=J
if "I is negative"
if "tolerance check goes here"
"Set each elemet in Ith row to -1"
end
if "I is postive"
if "tolerance check goes here"
"Set each elemet in Jth row to -1"
end
I'm worried that if the Jth row is -1, the the tolerance check is not going to work based on changing the base value of it when comparing it to other rows.
If anyone has an idea on how to accomplish this, I would be interested in hearing it.
I'm also thinking of just deleting the row in the if/else statement, but I had troubles getting that to work when trying before.
It's worth trying again though.
Thanks.
Edit:
The reason I would like to do this is because I'm looking at an orbit positions around a planetary body.
With these positions, my current MATLAB script takes each datapoint and determines which points show a large difference from a thermal perspective, so it might take a total of 5,000 datapoints are reduce it to 1,000 datapoints.
Then with these 1,000 datapoints, I input them into a thermal analysis program.
The reason I want to reduce these 1,000 points is because A. it takes a long time to run in the thermal analysis program, and B. a lot of the datapoints are similar such that I don't gain any significant insight on my system if it only travels 1m along its orbit, for example.
What I have currently is taking that 1,000 down to 100 datapoints, which is good, but I would like to make it such that I don't just remove all of the "second hump" in the sinusoid, but a few points from the "first hump" and a few from the "second hump", like the attached images show.
I want this just so there aren't that big of jumps in the curves, or if I want to look at a transient case, the big gaps won't cause issues either (although for now I'm only looking steady-state so haven't given transient a thought yet).
  4 个评论
Jon
Jon 2022-6-20
Sure thing, I'll explain the bigger picture in the main post as an edit.
Image Analyst
Image Analyst 2022-6-20
I'm not seeing the data attached. Are you sure you attached it? Or did you forget to attach it in your edit?
What about if you just divided the Y range up into, say, 20 intervals, then loop over each range, finding out what points are in that particular range, and then taking, say 5 or half or whatever fraction of them you want?
edges = linspace(min(y), max(y)+ 0.00001, 20);
for k = 1 : numel(edges) - 1
inrange = y >= edges(k) & y < edges(k+1)
randomIndexes = randperm(numel(inrange), 5); % Take 5 of them.
ySubSet = y(randomIndexes);
% etc.
end

请先登录,再进行评论。

采纳的回答

Jon
Jon 2022-6-20
I wanted to let you both know that what I psuedo-coded in my original post ended up working with random test data that I created to make the script run quicker.
I'm going to try it with the full data-set tomorrow, but for now I think it's okay to close this case.
Thanks for your help regardless.

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by