MATLAB: Difference between next two numbers

automationdifferencedrying centrifugeequal results

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 300×1 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

Best Answer

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.