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!