How can I rewrite this to get peak locations?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Star Strider
el 10 de Feb. de 2023
Editada: Star Strider
el 10 de Feb. de 2023
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 comentarios
Star Strider
el 14 de Feb. de 2023
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
el 10 de Feb. de 2023
Perhaps the islocalmax function with the dim input argument will meet your needs.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!