Problem with findpeaks 3D grid

4 Ansichten (letzte 30 Tage)
Miguel andres
Miguel andres am 9 Mai 2020
Kommentiert: Ameer Hamza am 10 Mai 2020
Hey all,
I have a velocity values over 720 time steps for a curvilinear grid (40x144x720). I would like to obtain the peak in all the grid points. One problem that I have is that the number of peaks are different in all the points.
I tried using the function findpeaks, and if I discretize one point, it works well. My problems is when I try the loops and I don´t know really well I storage the output.
u_atl=squeeze(u(:,:,1,:));%size(40x144x720)
n=720; %time steps
i=zeros(40,144);%latitud and longitud
j=zeros(40,144);
for i=1:40
for j=1:144
for k=1:n
[pval(i,j,k),ploc(i,j,k)]=findpeaks(u_atl(i,j,k),'minpeakdistance',6);
[peak_ebb(i,j,k),ploc(i,j,k)]=findpeaks(-u_atl(i,j,k),'minpeakdistance',6);
end
end
end
I'm pretty new in Matlab so I hope you can help me.
Thanks in advice,
Miguel.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 9 Mai 2020
Bearbeitet: Ameer Hamza am 9 Mai 2020
findpeaks() needs a vector, whereas you are passing it a scalar. It will not work properly. Also, if the number of peaks is different, then you will need to use a cell array to store all values. Normal arrays can only hold values when all the dimensions are of the same length. Try something like this
u_atl=squeeze(u(:,:,1,:));%size(40x144x720)
pval = cell(40, 144);
ploc = cell(40, 144);
peak_ebb = cell(40, 144);
ploc_ebb = cell(40, 144);
for i=1:40
for j=1:144
[pval{i,j},ploc{i,j}] = findpeaks(squeeze(u_atl(i,j,:)), 'minpeakdistance', 6);
[peak_ebb{i,j},ploc_ebb{i,j}] = findpeaks(-squeeze(u_atl(i,j,:)), 'minpeakdistance', 6);
end
end
  6 Kommentare
Miguel andres
Miguel andres am 10 Mai 2020
Yeah, seems that it works!!
Thank you really much.
Ameer Hamza
Ameer Hamza am 10 Mai 2020
I am glad to be of help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by