MATLAB: How to match a value on a matlab plot

peak

I have identified the first peak value in my dataset. I'd like to know the first x-value at the point at which this peak y-value occurs again. Any suggestions? p

Best Answer

Use the ‘locs’ value:
[pks,locs] = findpeaks(Voltage, 'MinPeakDist',2000, 'NPeaks',1);
peakTimes = Time(locs);
See the plot call in my previous code to demonstrate how to do this.
EDIT
‘I'd like to determine x (time) the next time 1.4147 (y, voltage) occurs.’
This will give all the ‘Voltage’ and ‘Time’ values that equal or exceed the initial peak value:
[D,S,R] = xlsread('Data.xls');
Time = D(:,1);
Voltage = D(:,2);
[pks,locs] = findpeaks(Voltage, 'MinPeakDist',2000, 'NPeaks',1, 'MinPeakHeight',1.2);
VoltageThreshold = Voltage - pks*0.99;
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
zx = zci(VoltageThreshold);
TimeNew = Time(zx); % Time Vector, Voltage >= VoltageThreshold
VoltageNew = Voltage(zx); % Voltage Vector, Voltage >= VoltageThreshold
figure(1)
plot(Time, Voltage)
hold on
plot(Time(locs), Voltage(locs), '+g')
plot(TimeNew, VoltageNew, '+r')
hold off
grid