Plot the result of findpeaks.

7 次查看(过去 30 天)
Dear all,
I captured human motion data of side-by-side walking in numerous data sets. The filtered data looks like that:
Now, I used the function findpeaks to find peaks and location of the filtered data and stored it in a struct.
for i = 1:numel (data)
[pks_1,locs_1] = findpeaks (data(i).filt_first_last_transposed (1,:)); % find peak and location
data(i).peaks_1 = pks_1; % store it into the struct 'data' with the field name peaks_1
data(i).locs_1 = locs_1; % see above
[pks_2,locs_2] = findpeaks (data(1).filt_first_last_transposed (2,:));
data(i).peaks_2 = pks_2;
data(i).locs_2 = locs_2;
end
I am struggling how to plot the filtered data including the identified pks. In doing so, I can inspect, if identified peaks are correct.
Any suggestions or an easier way to get results?
Regards, Jonas
  1 个评论
Image Analyst
Image Analyst 2021-12-28
编辑:Image Analyst 2021-12-28
You forgot to attach your data. Make it easy for us to help you, not hard.
Is your second curve supposed to be data(1) and not data(i)?

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2021-12-28
Perhaps this:
for i = 1:numel (data)
% Find peaks for first column of the i'th data set.
col1 = data(i).filt_first_last_transposed (1,:);
[peakValues1, indexesOfPeaks1] = findpeaks(col1); % find peak and location
data(i).peaks_1 = peakValues1; % store it into the struct 'data' with the field name peaks_1
data(i).locs_1 = indexesOfPeaks1; % see above
% Plot them
hold off;
plot(col1, 'b-', 'LineWidth', 2);
hold on;
plot(indexesOfPeaks1, peakValues1, 'cv', 'MarkerSize', 15, 'LineWidth', 2)
% Find peaks for second column of the i'th data set.
col2 = data(i).filt_first_last_transposed (2,:);
[peakValues2, indexedOfPeaks2] = findpeaks(col2);
data(i).peaks_2 = peakValues2;
data(i).locs_2 = indexedOfPeaks2;
% Plot them
plot(col2, 'r-', 'LineWidth', 2);
hold on;
plot(indexesOfPeaks2, peakValues2, 'mv', 'MarkerSize', 15, 'LineWidth', 2)
end
If it doesn't work, attach data in a .mat file
save('answers.mat', 'data');
with the paperclip icon.
  1 个评论
Jonas Bender
Jonas Bender 2022-1-3
Dear Mr/Mrs,
thanks for your helpful advice. It works perfectly.
Jonas

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by