Index in position 2 is invalid. Array indices must be positive integers
or logical values.
Error in calculation (line 58)
Upeak(count+1,2*eta(i-1))= t(j);
time
Error in main (line 27)
[t,S,i_arr,Upeak,Lpeak]=calculation(m,time,tsd,k,eta);
function [t,S,i_arr,Upeak,Lpeak] =calculation(m,time,tsd,k,eta)
tsd = 0.01;
m = 2.5;
k = 175;
time = [0 4];
eta = [0.015 0.09 1]
eta2 = [0.02 1 0.08 2 1.5 0];
t=(0:tsd:4);
A = 5;
w0= sqrt(k/m) ;
i_arr=[];
Upeak=[];
Lpeak=[];
for i=2:length(eta)
count = 1;
count1 = 1;
if eta(i) < 1
Upeak(1,2*i-1)=0;
Lpeak(1,2*i-1)=0;
Upeak(1,2*i)=A;
Lpeak(1,2*i)=-A;
i_arr=[i_arr eta(i)];
end
wd = w0.*(sqrt(1-eta(i).^2)) ;
for j=2:length(t)
S(i,j) = exp((-eta(i)).*w0.*t(j)).*(A.*cos(wd.*t(j))) ;
if eta(i) < 1 && t(j) > 3
right = S(i,j)
middle = S(i,j-1)
left = S(i,j-2)
if middle > left && middle > right
Upeak(count+1,2*eta(i-1))= t(j);
Upeak(count+1,2*eta(i))=S(i,j-1) ;
count=count + 1 ;
end
if middle < left && middle < right
Lpeak(count+1,2*(i-1)) = t(j) ;
Lpeak(count+1,2*(i))=S(i,j-1) ;
count1= count1 + 1;
end
end
end
end
if i == length(eta2)
fprintf(' Upeak Data Points \n')
fprintf('%3.3d \n', Upeak());
else
fprintf(' Lpeak Data Points \n')
fprintf('%3.3d \n', Lpeak());
end
end