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.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 9 日
編集済み: Ameer Hamza 2020 年 5 月 9 日

0 投票

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 件のコメント

Miguel andres
Miguel andres 2020 年 5 月 9 日
Hi,
I tried that and yeah, the error that appear is that findpeaks spect to use a vector.
But I don't understand why when I discretize one point it works. The loops should select point after point.
I attach here the values that I want for a selected point. Maybe you have another idea how to obtain them in all the points.
Thank you really much again.
Ameer Hamza
Ameer Hamza 2020 年 5 月 9 日
Is this one signal from the 40x144x720 matrix? Do you get an error when you run my code?
Miguel andres
Miguel andres 2020 年 5 月 9 日
This signal is if I do A=squeeze(u_atl(25,25,:)). So A is 720x1.
If I do [value,location]=findpeaks(A) it works. The plot is:
plot(A)
hold on
scatter(location,value)
The problem iswhen I have to do the loops, something is wrong but I don´t know what.
Thank you.
Ameer Hamza
Ameer Hamza 2020 年 5 月 9 日
Try the updated code in my answer. There was a mistake.
Miguel andres
Miguel andres 2020 年 5 月 10 日
Yeah, seems that it works!!
Thank you really much.
Ameer Hamza
Ameer Hamza 2020 年 5 月 10 日
I am glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by