For instance, if I was plotting Scope (x) and Temperature (y), why can't I use the following code: [pks,locs] = findpeaks(Temperature)? Matlab tells me that there is the following error: Error using findpeaks>parse_inputs (line 131) Expected a string for the parameter name, instead the input type was 'double'. Error in findpeaks (line 71) [X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(Xin,varargin{:}); It gives me the peaks when I simply use findpeaks(Temperature), but I need the corresponding x values to compute as well.
John Michell answered .
2025-11-20
The error occurs because findpeaks expects additional inputs (parameters) to be specified as name-value pairs, and you might have accidentally passed a numeric input that caused confusion.
If you want both the peak values (y locations) and their corresponding x locations, you need to pass the x values explicitly as the first argument to findpeaks. Here's the correct way to do it:
[pks, locs] = findpeaks(Temperature, Scope);
Temperature: Your y values (the data you want to find peaks for).Scope: Your x values (the corresponding x-axis data for the peaks).The output will be:
pks: The peak values in the Temperature array.locs: The corresponding x values from the Scope array where the peaks occur.
Scope = 1:0.1:10; % Example x-axis values
Temperature = sin(Scope) + 0.1*rand(size(Scope)); % Example y-axis values with noise
[pks, locs] = findpeaks(Temperature, Scope);
% Plot results
plot(Scope, Temperature);
hold on;
plot(locs, pks, 'ro'); % Mark peaks
xlabel('Scope');
ylabel('Temperature');
title('Peaks in Temperature Data');
Scope and Temperature have the same length.findpeaks with both y and x inputs to get the correct x locations for the peaks.
[pks, locs] = findpeaks(Temperature, Scope, 'MinPeakHeight', 0.5, 'MinPeakDistance', 10);
Let me know if you need further clarification!