% Code to compute L local maximas of a function

function [val pos] = local_max(x,L)

[val_a pos_a] = findpeaks(x);
val = ones(L,1);
pos = ones(L,1);
[val_max, loc_max] = sort(val_a, 'descend');
r = min(L,length(val_a));
for i = 1:r
    val(i) = val_max(i);
    pos(i) = pos_a(loc_max(i));
end
    
end


