for loop not working

1 view (last 30 days)
Aleena James
Aleena James on 7 Dec 2019
Commented: Star Strider on 7 Dec 2019
Hi, I have this signal and I want to find out the mean between the peaks. I know the x and y values at the peaks. this is my code
y1=locs+10; %wants few points before and after peaks to avoid mean being affected by the peak values thus +10
y2=locs-10; %locs is the y position of the peaks
for k= 1:length(locs)-1
ROI=transpose(y1(k):y2(k+1)); %transpose is the whole signal, trying to extract each region between peaks
mean2=mean(ROI);
end
The code works for one loop (i.e.k=1) but wont repeat it. But if I use 'ROI=transpose(y1(k):y2(k+1))' in the command window and physically type k=2 and 3 it will work. so I guess i'm missing a step in the for loop. any suggestions would be appreciated. Thanks in advancepks per revolution.jpg

Accepted Answer

Star Strider
Star Strider on 7 Dec 2019
We o not have your entire code. Note that the transpose call is not necessary, since the mean funciton also accepts a dimension argument, where 1 is down the rows for each column (the default) and 2 is across columns, taking the mean of each row.
  4 Comments
Aleena James
Aleena James on 7 Dec 2019
thank you so much it works:)
Star Strider
Star Strider on 7 Dec 2019
As always, my pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!