Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Adam
Adam am 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?

Akzeptierte Antwort

Markus
Markus am 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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by