How can I try different input values to findpeaks while ignoring errors?

I'm trying to use the findpeaks command on multiple waveforms in a for loop. In the findpeaks inputs, I'm using 'MinPeakDistance' to filter out unwanted values. My problem is the scalar value that goes with 'MinPeakDistance' changes with every loop iteration. Sometimes I get an error that says the value must be <100, sometimes <50.
I want to be able to loop through all possible values for each iteration of my outer for loop and instead of detecting an error and discontinuing to execute the code, it just goes to the next value and sees if that one works and as soon as it does, move on to the next iteration of the outer for loop. Here is what I have so far...
A is a cell vector of the names of the figures I'm pulling data from.
PeakVec = [];
for i = 1:length(A)
open(A{i});
h = gcf;
axesObjs = get(h, 'Children'); % axes handles
dataObjs = get(axesObjs,'Children'); % gets all data
objTypes = get(dataObjs,'Type');
freq = get(dataObjs,'XData'); % frequency data
power = get(dataObjs,'YData'); % power data
close(h) % closes figure
% find peaks of each figure and their corresponding frequencies
[peaks,loc] = findpeaks(power,'MinPeakDistance',99,'MinPeakProminence',1e-4);
PeakVec = [PeakVec peaks];
end
I was doing some reading and I think the "try/catch" command might work but I'm not sure. Any ideas?

Answers (1)

You’ve not shared your data, so I’m guessing here.
The findpeaks function allows you to define the independent variable as the second argument, before the name-value pair arguments. If your independent variables scale approximately with the peak distances, then might be possible to define a single value for 'MinPeakDist' in terms of the independent variable rather than the default index values.

Products

Release

R2017b

Asked:

on 2 Aug 2018

Answered:

on 2 Aug 2018

Community Treasure Hunt

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

Start Hunting!