difference between next two numbers

2 views (last 30 days)
I am looking for a solution to this chemical matlab problem to try to automate a drying centrifuge. I get values from a mass spectrometer in a 300x1 table. The first values are very low (0.01 or 0.02) and after a while the mass spectrometer detects the solvent and gives higher values (something like 0.79 and dropping more or less exponentially) back untill this is again 0.01. Now for my automation excercise I want to calculate again and again the difference between the next two numbers untill this difference is 5 or more times equal to 0 (so we can conclude the product is dry).
for example like in this table:
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.79
0.54
0.33
0.10
0.05
0.01
0.01
0.01
0.01
0.01
0.01

Accepted Answer

Star Strider
Star Strider on 29 Mar 2019
One approach:
v = [0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.79
0.54
0.33
0.10
0.05
0.01
0.01
0.01
0.01
0.01
0.01];
[vmax,idx] = max(v); % Find Single Peak
vdif = diff(v(idx:end)); % Calculate Differences From Peak To End Of Vector
isdry = nnz(vdif == 0) >= 5; % Sample Is Dry If ‘isdry’ == 1
This assumes that there is only one peak. If there are more, the findpeaks function and a loop would be necessary.
  15 Comments
Jordi De Cuyper
Jordi De Cuyper on 17 Apr 2019
I'm trying to optimize the "difference between next 2 points" method you posted, and I came to the problem that in some cases in the reality, the maximum peak value is not always a peak. Sometimes it rises to a peak value, then keeps this peak value for some time (let's say 10 minutes), and afterwards it has the typical exponential drop like in the example (so the 0.79 value that keeps repeating for multiple times before it drops). I want to implement some code that also keeps in mind that the model only needs to start after this maximum value starts to drop. Do you have any idea how you could do this?
Regards,
Jordi
Star Strider
Star Strider on 17 Apr 2019
The islocalmax (link) function (R2017b and later releases) has that capability. Also consider findpeaks if you have more than one peak The find function may also be an option. I’m not aware of any other functions that would be able to do that.

Sign in to comment.

More Answers (1)

Stephan
Stephan on 29 Mar 2019
Hi,
you may want to use the diff function.
Best regards
Stephan

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!