for loop not working
1 view (last 30 days)
Show older comments
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 advance
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!