- One should be careful with syntaxes like pks(ii+osc(ii)) and check whether ii+osc(ii) becomes zero or negative at any step.
- One should check whether the array on which ii is iterating (i.e., time and pks in this case) has a non-zero length.
Related to the findpeaks() function (Array indices must be positive integers or logical values.)
3 次查看(过去 30 天)
显示 更早的评论
I would like to embed below oscillation time formula in the logarithmic decrement formula where
Oscillation time:
I have a time vector time=[1x13094] and
for ii=1:length(time)
osc = diff(time); %oscillation period
end
i have created a oscillation period vector osc=[1x13093] by substracting consecutive time elements.
Logarithmic decrement:
Where y(t) are equal to peaks vector pks=[1x183] and pks vector coming from an accelaration vector acc=[1x13094] with findpeaks function:
[pks,locs]=findpeaks(acc);
Now, i want to use osc and pks vectors to calculate logarithmic decrement.
for ii=1:length(pks)
delta(ii)=log((pks(ii))/(pks(ii+osc(ii))));
end
When i try this code i get a error message 'Array indices must be positive integers or logical values.' How can i overcome this error? Thank you in advance.
0 个评论
回答(1 个)
Tanmay Das
2021-8-5
MATLAB does not support negative or zero indices in arrays. You can debug your code by placing Breakpoints at required location and then executing it step by step to know where negative or zero value is being passed as an index in the array. It is advised to follow a few things while passing a variable as an index to an array:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!