How can I rewrite this to get peak locations?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have this
amps = arrayfun(@(h2) max((findpeaks(udata(h2, :), x) < 0.99)...
.* findpeaks(udata(h2, :), x)), 1:size(udata, 1));
And I want to rewrite it to get peak locations. When I call x(amps) it gives a logic error...
댓글 수: 0
답변 (2개)
Star Strider
2023년 2월 10일
편집: Star Strider
2023년 2월 10일
The locations are the second output from findpeaks, so I doubt that arrayfun will do what you want.
I would do something like this —
udata = randn(10); % Create 'udata' Array
for h2 = 1:size(udata,2)
[pks,locs] = findpeaks(udata(h2, :));
pksc{h2,:} = pks; % Cell Array Of Peak Values
locsc{h2,:} = locs; % Cell Array Of Location Values
end
Lv = cellfun(@(x)x<0.99, pksc, 'Unif',0) % Cell Array Of Logical Vectors
pksm = cellfun(@(x,y)x(y), pksc, Lv, 'Unif',0) % Peak Values Result
locsm = cellfun(@(x,y)x(y), locsc, Lv, 'Unif',0) % Location Values Result
This will store the ‘pks’ and ‘locs’ vectors in their respective cell arrays. Process them appropriately later.
The ‘Lv’ (logical vector cell array) can have more than one condition, so that you can use a range of values such as:
@(x)(x<0.99) & (x>0.5)
if that is what you want to do. The rest of the code is unchanged.
EDIT — Corrected typographical errors.
.
댓글 수: 6
Star Strider
2023년 2월 14일
That means that there are no peaks in that column that meet the criteria. You can verify that by looking at the ‘pksc’ cell for that particular column:
pksv = pksc{column_number}
You can see that also occurs in my demonstration in my previous Comment. There may not be any peaks in a particular column that meet the criteria, and in that instance, my code assigns the cell as NaN (all detected peaks are false).
Steven Lord
2023년 2월 10일
Perhaps the islocalmax function with the dim input argument will meet your needs.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!