Guide me what is wrong in this code,i am trying to retrieve 3 values from function and trying to place those values

1 vue (au cours des 30 derniers jours)
load('beamdata.mat');
fs=1000;
Nd=length(Az(:,1));
Ns=length(Az(1,:));
n=3;
w=zeros(Nd*n,1);
for i=1:1:Nd
w((n*(i-1)+1):(n*i),1)=find_mode_freq(Az(i,:),fs,n);
end
function [w]=find_mode_freq(data,fs,n)
N=length(data(1,:));
data=fft(data,N);
pyy=data.*conj(data)/N;
pyy_half=pyy(1:(floor(N/2)+4));
f=(fs/N)*(0:(floor(N/2)+3));
[~,locs]=findpeaks(pyy_half,'sortstr','descend','minpeakdistance',20);
w=zeros(n,1);
for i=1:1:n
w(i)=f(locs(i))*2*pi;
end
end
this error i am getting
Index exceeds the number of array elements (0).
Error in find_mode_freq (line 14)
w(i)=f(locs(i))*2*pi;
Error in ex2 (line 11)
w((n*(i-1)+1):(n*i),1)=find_mode_freq(Az(i,:),fs,n);
  6 commentaires
Walter Roberson
Walter Roberson le 23 Avr 2019
That .mat file would make it easier for us to debug the problem.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Avr 2019
The beamData Az (acceleration in the Z direction) starts out as all zero. There are no peaks in the first row, so findpeaks() returns empty. The code does not expect that.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by