How to define RDT function in Matlab?

조회 수: 11 (최근 30일)
Hasantha Dissanayake
Hasantha Dissanayake 2020년 10월 28일
댓글: Jon 2020년 10월 30일
I used following code for my calculations but I think it has an error.
Code
function [R,t] = RDT(y,ys,T,dt)
%
% [R] = RDT(y,ys,T,dt) returns the free-decay response (R) by
% using the random decrement technique (RDT) to the time serie y, with a
% triggering value ys, and for a duration T
%
% INPUT:
% y: time series of ambient vibrations: vector of size [1xN]
% dt : Time step
% ys: triggering values (ys < max(abs(y)) and here ys~=0)
% T: Duration of subsegments (T<dt*(numel(y)-1))
% OUTPUT:
% R: impusle response function
% t: time vector asociated to R
%
% Author: E. Cheynet - UiB - last modified 14-05-2020
%%
if T>=dt*(numel(y)-1)
error('Error: subsegment length is too large');
else
% number of time step per block
nT = round(T/dt); % sec
end
if ys==0
error('Error: ys must be different from zero')
elseif or(ys >=max(y),ys <=min(y)),
error('Error: ys must verifiy : min(y) < ys < max(y)')
else
% find triggering value
ind=find(diff(y(1:end-nT)>ys)~=0)+1;
end
% construction of decay vibration
R = zeros(numel(ind),nT);
for ii=1:numel(ind)
R(ii,:)=y(ind(ii):ind(ii)+nT-1);
end
% averaging to remove the random part
R = mean(R);
% normalize the R
R = R./R(1);
% time vector corresponding to the R
t = linspace(0,T,numel(R));
end
Error msg
>> RDT
Not enough input arguments.
Error in RDT (line 18)
if T>=dt*(numel(y)-1)
can anybody suggest me a solution for this problem?
Thank You.!
  댓글 수: 2
Jon
Jon 2020년 10월 28일
You can use the code button on the MATLAB Answers toolbar to nicely format your code.
E. Cheynet
E. Cheynet 2020년 10월 29일
Hi Hasantha,
There is a Matlab livescript on Matlab File Exchange, which shows how to use the function RDT: https://se.mathworks.com/matlabcentral/fileexchange/55557-damping-ratio-estimation-from-ambient-vibrations-sdof?s_tid=srchtitle

댓글을 달려면 로그인하십시오.

답변 (1개)

Jon
Jon 2020년 10월 28일
편집: Jon 2020년 10월 28일
You need to call the function with its arguments.
You just typed rdt on the command line. You must first assign the variables y,ys, T, and dt and then type on the command line:
R= rdt(y,ys,T,dt)
Note it is not necessary to use the same variable names on the command line as in the function definition, so assuming a,b,c and d were assigned appropriate values you could also call the function using
R= rdt(a,b,c,d)
  댓글 수: 1
Jon
Jon 2020년 10월 30일
Hi Did this answer your question? If so please accept the answer so that others with a similar question will know that an answer is available.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by