How can I fit a curve at the bottom of the plot below?

I have the attached dataset and I want to fit a curve at the bottom of the curve. See the attached photo. The original data is in blue and the fit is that in black.
Sample data is attached. Thank you in advance

 Accepted Answer

You can use boundary,
y=readmatrix('data.txt');
x=(1:numel(y))';
k=boundary(x([1:end,1]), y([1:end,1]));
k=k(diff(k)>0);
plot(x,y, x(k),y(k))

5 Comments

Unfortunately when i apply this on my data I'm getting this. The blue line is the data and the black is what I require but im getting the orange line as fit.
The data in y.txt doesn't match your posted plot at all. Regardless, you can decrease the shrink factor,
to get closer to what you want.
y=readmatrix('data.txt');
x=(1:numel(y))';
S=[1,0.7,0];
for s=S
k=boundary(x([1:end,1]), y([1:end,1]),s);
k=k(diff(k)>0);
plot(x(k),y(k),'-.');hold on
end;
legend("s="+S); xlim([100,400])
I attached the data with the name 'y.txt' earlier you can refer to it. In y.txt the data has two columns you can disregard the time column and treat the 'data' column exactly as you did with 'data.txt'. This is exactly what I did and had the second plot i posted.
Ok, but what help do you still require? As you can see below, the recommendations from my last comment work for y.txt as well.
[~,y]=readvars('y.txt');
x=(1:numel(y))';
S=[1,0.7,0];
for s=S
k=boundary(x([1:end,1]), y([1:end,1]),s);
k=k(diff(k)>0);
plot(x(k),y(k),'-.');hold on
end;
legend("s="+S); xlim([100,400])
works great when s=0, Thank you very much

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023a

Asked:

on 4 Jul 2023

Edited:

on 4 Jul 2023

Community Treasure Hunt

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

Start Hunting!