Error when calling function
이전 댓글 표시
Im trying to calculate the 'Zero Crossings' in a sample signal with the below code.
When I try calling the function in the command window using 'zc = ZeroCrossing(t,emg6);' i get an error that says "Attempt to execute SCRIPT ZeroCrossing as a function."
I'd be grateful if someone can shed some insight on this.
Fs=200;
samples=0:2186; %number of data points in matrix
t = samples/Fs; % Time Vector (seconds)
t(:,[1]) = [];
function zc_idx = ZeroCrossing(t,emg6)
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zx = zci(emg6);
zc_idx = zeros(numel(zx),1); % initialise the zero crossing indices
for i = 1:numel(zx)
idx = max([1 zx(i)-1]):min([zx(i)+1 numel(emg6)]);
x_range = t(idx);
y_range = emg6(idx);
zc_idx(i) = interp1( y_range(:), x_range(:), 0, 'linear', 'extrap' ); % returns the approximate zero crossing Indices of argument vector
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!