Asked by Preshit Limje
on 18 Sep 2019 at 11:26

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

Answer by Star Strider
on 18 Sep 2019 at 11:56

Accepted Answer

Star Strider
on 18 Sep 2019 at 14:48

This was slightly more complicated than I originally thought it would be.

The Code —

[num,txt] = xlsread('test 1.xlsx');

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
on 18 Sep 2019 at 15:12

Hello Strider,

Thanks a lot. I much appreciate your help for solving this problem.

Star Strider
on 18 Sep 2019 at 15:17

As always, my pleasure!

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.