Repeat a function n times where n is the number of peaks

1 vue (au cours des 30 derniers jours)
Adam
Adam le 4 Sep 2013
Firstly, I'm sorry that this isn't a very brief question. I'm not very experienced with MATLAB and have run into a problem.
I have used a script that finds the peaks and troughs in a given dataset and then produces two matrices (maxtab for peaks, mintab for troughs) with two columns each. The first column contains the x value at which the peak/trough can be found and the second column contains the actual value of the peak/trough.
What I now need to do is multiply the peak-to-peak value by the original dataset. What this means is that firstly, I need a piece of code that will subtract the first trough value from the first peak value, then the first trough value from the second peak value, then the second trough value from the second peak value, then the second trough value from the third peak value, then the third trough value from the third peak value and so on.
What I then need to do is create a vector where each peak to peak value is repeated for every datapoint in the range of that peak to peak value. This would mean that if, say, the x value for the first peak was 1, then the x value for the first trough was 15, then the x value for the second peak was 20, I would need to repeat the first peak to peak value 15 times, then the second peak to peak value 5 times. I want to be able to do this automatically depending on the number of peaks and troughs in the dataset.
I've tried to find ways to do both of these things and haven't had any success. Can anyone offer any help?

Réponse acceptée

Markus
Markus le 4 Sep 2013
i am not sure, if i understand the discription. but, if you n is the numer of peaks, than it should be possible to count the peaks.
for i=1:n
function
end
if your want the value of the peak than it would be necessary to create a vector with all values
nPeaks=[1 15 20];
for i=nPeaks
function
end
hope this helps
  1 commentaire
Adam
Adam le 4 Sep 2013
That's fantastic, I have it working now, thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by