How to connect minimum points into a line?

2 views (last 30 days)
How could I connect all minimums on x-ray spectrum into a one straight line? I'm attaching an exemplary spectrum file.

Accepted Answer

John D'Errico
John D'Errico on 27 Jan 2018
Edited: John D'Errico on 27 Jan 2018
n = length(x);
M = [x,ones(n,1)];
C = lsqlin(M,y,M,y);
C =
-20.501
1191.8
plot(x,y,'b.',x,C(2) + C(1)*x,'r-')
grid on
If you actually meant something different, like how do you find ALL the local minima, then connect them with straight lines, then you need to use tools like findpeaks, then just call plot.
  1 Comment
you dah
you dah on 31 Jan 2018
Unfortunately, it seems not to work for the entire spectrum. Matlab stops working when I enter the code.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!