## Related to calculate average within particular range of graph

### Preshit Limje (view profile)

on 18 Sep 2019 at 11:26
Latest activity Commented on by Star Strider

### Star Strider (view profile)

on 18 Sep 2019 at 15:17

### Star Strider (view profile)

Hello,
I am new to matlab. I got signals from the sensors for force with respect to time. The values of time and force are stored in respetive columns after importing it in matlab through excel file. Thus, I need to find the average values within particular range of values in graph (highlighted in red colour). Can someone help?
Thanks
Preshit

### Star Strider (view profile)

on 18 Sep 2019 at 11:56

Use the negative of your signal (essentially flipping it upside-down) so the sharp dips are now peaks. Then use either findpeaks or islocalmax to isolate the indices of the peaks. Use those indices to calculate the mean between them. (If I had your signal, I could write code specific to your problem. With only a picture, I can only describe the approach.)

Show 1 older comment
Star Strider

### Star Strider (view profile)

on 18 Sep 2019 at 14:48
This was slightly more complicated than I originally thought it would be.
The Code —
time=num(:,1);
Fz=num(:,5);
Fzei = find(Fz > 270); % Edit ‘Fz’ To Eliminate Irrelevant Data
[pks,locs] = findpeaks(-Fz(Fzei), 'MinPeakProminence',100); % Find Sharp Dip Indices
locsi = Fzei(locs); % Map ‘lods’ To Edited Data Indices
for k = 1:numel(locsi)-1
idxrng{k} = (locsi(k)+1):(locsi(k+1)-1);
seg_mean(k) = mean(Fz(idxrng{k}));
end
figure
plot(time,Fz);
hold all
plot(time(locsi), -pks, 'vr')
for k = 1:numel(idxrng)
plot(time(idxrng{k}), ones(size(idxrng{k}))*seg_mean(k), '-r', 'LineWidth',2)
end
hold off
grid
xlabel('Time')
ylabel('F_z')
legend('Data','Valleys','Segment Mean', 'Location', 'NW')
The Plot —
This appears to give the requestted information. The segment means are in the ‘seg_mean’ vector. Experiment to get other results.
Preshit Limje

### Preshit Limje (view profile)

on 18 Sep 2019 at 15:12
Hello Strider,
Thanks a lot. I much appreciate your help for solving this problem.
Star Strider

### Star Strider (view profile)

on 18 Sep 2019 at 15:17
As always, my pleasure!