I'm trying to create a for loop that will calculate avg = mean(var(n:(n+500))) for all values of n. What I mean by that is that I want to average over the range from n to n+500 for each value of n, so if n has 500 values, I want to average over 500 different ranges. Mean is the function, var is a variable loaded to the workspace, and n is the linear index of values of the variable. I'm a pretty beginner-level matlab user and have almost no experience with looping, hence the difficulties.
Here's the code I have created, which yields only a single value for avg (the result for n=1):
load data.mat[peaks, locs] = findpeaks(data1);locs1 = locs-400; locs2 = locs+400;for locs = locs(1:end);avg1 = mean(abs(data1(locs_minus:locs)));avg2 = mean(abs(data1(locs:locs_plus)));end
Any advice would be greatly appreciated. It seems like a very simple problem that I'm just too ignorant of matlab to figure out.
Best Answer