Finding x value at 10% of max y value, after the max
5 次查看(过去 30 天)
显示 更早的评论
I am trying to find the x value at 90% of my max y value, after the peak. Below is something I have tried using other MATLAB Answers and recieved an error message for (probably because I am not modifying them correctly). I am also attaching a figure of my curves. In my code I am only looking at the first blue curve. It looks like I should get a value around 41 (mm). If I leave out the "*(9/10)", I get 39 which is just the peak, but I need to get to 90% of the peak. Please let me know if you could help! Thank you in advance!
"Depth" is my x data and "SeventyMeV" is my y data.
[TenthmaxYValue, indexAtMaxY] = max(SeventyMeV)*(9/10);
xValueAtMaxYValue = Depth(indexAtMaxY(1))
0 个评论
回答(2 个)
ICR
2020-11-15
编辑:ICR
2020-11-15
% Find the max value for your data
maxVal = max(SeventyMeV);
maxVal90 = round(maxVal)*(9/10); % if you have enough datapoints remove round.
% Orelse you can use round or floor whichever suits you
[row,col] = find(SeventyMeV == maxVal90);
valAt90 = SeventyMeV(row(2)); % this will be your value of 90% after the peak
depthAt90 = depth(row);
6 个评论
Star Strider
2020-11-15
It would be necessary to have a sample of your data to write specific code, so I will simply describe the procedure.
Second, use the ‘locs’ index values (second output of findpeaks) to determine the indices of the peaks.
v90(k) = interp1(y(locs(k)+[0 1]), x(locs(k)+[0 1]), 0.9*y(pks(k)), 'linear','extrap')
for each peak for k = 1:numel(locs).
I cannot figure out a way to simulate the missing data, so I am labeling this UNTESTED CODE. It should work, however it may need to be tweaked to work with your data.
6 个评论
Star Strider
2020-11-15
Again, this is a problem of not having your data to work with.
Solve the NaN probllems by adding 'extrap' to the interp1 call:
v90(k) = interp1(y(locs(k)+[0 1]), x(locs(k)+[0 1]), 0.9*y(locs(k)), 'linear','extrap') % X-Values At 90% After Peak
This may result in ‘interesting’ extrapolated values!
Another option (with or without 'extrap') is:
v90(k) = interp1(y(locs(k)+[0:2]), x(locs(k)+[0:2]), 0.9*y(locs(k)), 'linear') % X-Values At 90% After Peak
However without at least a sample of your data, I’m just left to guess as to what the probllems could be.
I leave it to you to experiment with these options.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!