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

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-4-23
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.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by