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:

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.
回答(2 个)
Star Strider
2019-12-26
0 个投票
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
2019-12-26
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
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!