Local max of a single-column array

Hi! I have a vector with 3 amplitudes and very similar values in between. If I plot the vector this is what MATLAB shows:
Anotación 2019-12-26 175729.jpg
Is there any specific function that can take the 3 main values and save them into another variable?
Tried localmax() and findpeaks() but both give me an array full of zeros.

Answers (2)

Star Strider
Star Strider on 26 Dec 2019
Check the logical vector that the islocalmax function returns. I doubt if is entirely zeros, so use the find function to return the numeric indices from the logical vector.
Alternatively, upload your data. A specific solution is not possible without it.
Unfortunately you're preventing us from trying things because you didn't attach your data and explain things better. It looks like you don't want local/regional max or peaks. It seems like you want to know the 3 values. So what I'd do is to use kmeans(), something like this untested code:
% Get indexes for the 3 main signal value ranges.
numClasses = 3; % Whatever...
indexes = kmeans(signal, numClasses);
theMeans = zeros(1, numClasses); % Preallocate space for the means.
% Find the means for each
for k = 1 : numClasses
% Get a logical vector saying what indexes of the signal
% are thought to belong to this class.
theseClassIndexes = (indexes == k);
% Get the mean of ONLY this class.
theMeans(k) = mean(signal(theseClassIndexes))
end

Products

Release

R2018b

Asked:

on 26 Dec 2019

Answered:

on 26 Dec 2019

Community Treasure Hunt

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

Start Hunting!