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

조회 수: 1 (최근 30일)
Adam
Adam 2013년 9월 4일
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?

채택된 답변

Markus
Markus 2013년 9월 4일
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
Adam
Adam 2013년 9월 4일
That's fantastic, I have it working now, thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by