Effacer les filtres
Effacer les filtres

help error : Attempted to access i(1); index out of bounds because numel(i)=0.

2 vues (au cours des 30 derniers jours)
phan nam
phan nam le 15 Mai 2014
Commenté : phan nam le 15 Mai 2014
I don't understand what the error means (line 39). Any help would be appreciated!
Attempted to access i(1); index out of bounds because numel(i)=0.
Error in tsanam (line 39)
itrev(1)=((i(1)-1)+(0-tachsignal(i(1)-1))/(tachsignal(i(1))-tachsignal(i(1)-1)));
code:
function [tsadata, navgs,trev]=tsa(data,tachsignal,fsample,tachtype,ratio,ncycles,navgs)
clear all; clc;
monnang=load('50f.txt');
tachsignal=monnang(:,2);
ncycles=2;
ratio=0.097;
tachsignal = tachsignal - 2.5;
% find the portion of the tach vector that is zero or negative
% Exclude the first value to insure that (i-1)>=1
x=find(tachsignal(2:length(tachsignal))<=0)+1;
% find the zero crossings
xx=find(tachsignal(x-1)>0);
i=x(xx);
if ((ncycles/ratio)~=1)
% Determine indices for each ncycles of shaft of interest from tach cycles
% Note that the vector itrev when multipled by dt=1/fsample yeilds the
% zero crossing times starting with ??? <-can't read what was written here
m=floor(length(i)*ratio/ncycles);
itrev=zeros(m,1);
itrev(1)=((i(1)-1)+(0-tachsignal(i(1)-1))/(tachsignal(i(1))-tachsignal(i(1)-1)));
for p=2:m
sip=i(floor((p-1)*ncycles/ratio)+1);
itrevp=((sip-1)+(0-tachsignal(sip-1))/(tachsignal(sip)-tachsignal(sip-1)));
siq=i(ceil((p-1)*ncycles/ratio)+1);
itrevq=((siq-1)+(0-tachsignal(siq-1))/(tachsignal(siq)-tachsignal(siq-1)));
itrev(p)=itrevp+(itrevq-itrevp)*[(p-1)*ncycles/ratio-floor((p-1)*ncycles/ratio)];
end
else
%When ncycles/ratio=1
itrev =((i-1)'+(i - (i-1))'*(0-tachsignal(i-1))/(tachsignal(i)-tachsignal(i-1)));
end
%Determine radix 2 number such that number of points in resampled TSA waveform
%corresponds to a sample rate just greater than fsample
N=2^ceil(log2((mean(diff(itrev)))));
%Define the number of averages to perform
if nargin < 7
navgs = length(itrev)-1;
end
% resample vibe data using zero crossing times
%use the time vector to interpolate the vibe data
yy = zeros(1,N);
for k = 1:navgs
% select the subsection of the vector to operate on
x=floor(itrev(k)):ceil(itrev(k+1));
y=data(x);
% generate resample time values
itresample = (itrev(k):(itrev(k+1)-itrev(k))/(N-1):itrev(k+1));
% accumulate the vector values for each rev
yy = yy + spline(x,y,itresample);
end
% compute the average
tsadata = yy/navgs;

Réponses (1)

Julien Moussou
Julien Moussou le 15 Mai 2014
In your 50f.txt, the second column has values between -0.25 and +0.25.
The lines
monnang=load('50f.txt');
tachsignal=monnang(:,2);
(...)
tachsignal = tachsignal - 2.5;
make sure that tachsignal values are all negative, so that the later
xx=find(tachsignal(x-1)>0);
is empty.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by