How to get number of peaks and locs from different graphs that are plotted using a single for loop?

2 次查看(过去 30 天)
figure;
for k=1:length(x)
profile(k)=img(y(k),x(k));
plot(profile,'r-','LineWidth',2);
grid on;
ylim([0 2]);
end
This code giving me different plots. For each of the plot I am getting different peaks. How can individually calculate no of peaks and locs for each of the plot?

回答(1 个)

KSSV
KSSV 2018-7-16
Have a look on functions max and findpeaks.
  3 个评论
KSSV
KSSV 2018-7-16
iwant = cell(length(x)) ;
figure;
for k=1:length(x)
profile = img(y(k),x(k));
[pks,locs] = findpeaks(profile) ;
iwant{i} = pks ;
plot(profile,'r-','LineWidth',2);
grid on;
ylim([0 2]);
end
Zara Khan
Zara Khan 2018-7-16
Error using findpeaks Expected Y to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Instead its type was logical.
Error in findpeaks>parse_inputs (line 189) validateattributes(Yin,{'numeric'},{'nonempty','real','vector'},...
Error in findpeaks (line 131) [y,yIsRow,x,xIsRow,minH,minP,minW,maxW,minD,minT,maxN,sortDir,annotate,refW] ...
Error in ci_1 (line 33) [pks,locs] = findpeaks(profile);
This is the error I am getting . converting profile to double before using findpeaks still getting the same error

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by