Info
This question is closed. Reopen it to edit or answer.
Identifying certain x value of a graph when x is not dependent on y?
2 views (last 30 days)
Show older comments
Hi, I have plotted 2 columns of data from an excel sheet, I have identified several peaks and I would like to know the times associated with these peaks without just zooming in on each value. Basically is there a way to extract an x value given the graph, even though the x and y values are independent?
Similar code would be;
Time = xlsread('Data.xlsx', 'C2:C5000');
Time = Time/500;
Activity = xlsread('Data.xlsx', 'E2:E5000');
FilterActive = sgolayfilt(Activity, 5, 9); % can be removed
peaks = findpeaks(FilterActive, 'MinPeakHeight', 0.4);
plot(Time, FilterActive)
Im very new and inexperienced with coding, so any help or suggestions are welcome and appreciated, thanks.
0 Comments
Answers (1)
Star Strider
on 13 Mar 2017
Ask for a second output from findpeaks.
If you want the indices of the peaks, just use:
[peaks, peak_loc_idx] = findpeaks(FilterActive, 'MinPeakHeight', 0.4);
The ‘x’ values (in the actual units of ‘x’) will then be:
xval = x(peak_loc_idx);
corresponding to the ‘x’ value at each peak.
There are other ways to get the ‘x’ values directly. See the documentation for findpeaks for details.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!