Local max of a single-column array
Show older comments
Hi! I have a vector with 3 amplitudes and very similar values in between. If I plot the vector this is what MATLAB shows:

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
on 26 Dec 2019
0 votes
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.
Image Analyst
on 26 Dec 2019
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
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!