Subscript indices error, trying to calculate points on data curve

1 view (last 30 days)
Trying to calculate the midpoints between two adjoined extrema
tmp_mp = 0.5*(maxima(1:end,:)+minima(1:end-1,:))
mp(2:k+1,:)= data(tmp_mp);
maxima and minima come from a different function, problem is that the points calculated that way produce non integer indices. How can i fix this?
  2 Comments
Purushottama Rao
Purushottama Rao on 26 Aug 2015
Edited: Purushottama Rao on 26 Aug 2015
what does the second line in your code means? What do you expect mp to be?
Guillaume
Guillaume on 26 Aug 2015
To add to Puroshottama question, why do you expect the average of the maxima and minima to be integer?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 26 Aug 2015
mp(2:k+1,:) = mean([data(maxima(1:end,:)), data(minima(1:end-1,:))]);
If, that is, you want the average of the content, not content at the average location. If you want the content at the average location, you need to define what you want to happen if the sum of the two is odd so the average is an index half way through. Do you want to take the value at floor() of the index? At ceil() of the index? The average of the two?

Community Treasure Hunt

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

Start Hunting!