how to generate loop for given program

1 次查看(过去 30 天)
my dataset buttLoop3 is 24000x4 and i want to find out zero crossing of it...
i want to do below work in loop instead of typing it 4 time
zcd = dsp.ZeroCrossingDetector % calling function to detect zero count...
zcdOut = zcd(buttLoop3); % it counts how many times signals cross zero
y1 = buttLoop3(:,1) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi1 = zci(y1); % zero crossing indices command
for k = 1:numel(xi1)-1
ti1(k) = interp1(y1([xi1(k) xi1(k)+1]), t([xi1(k) xi1(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
y2 = buttLoop3(:,2) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi2 = zci(y2); % zero crossing indices command
for k = 1:numel(xi2)-1
ti2(k) = interp1(y2([xi2(k) xi2(k)+1]), t([xi2(k) xi2(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
y3 = buttLoop3(:,3) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi3 = zci(y3); % zero crossing indices command
for k = 1:numel(xi3)-1
ti3(k) = interp1(y3([xi3(k) xi3(k)+1]), t([xi3(k) xi3(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
y4 = buttLoop3(:,4) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi4 = zci(y4); % zero crossing indices command
for k = 1:numel(xi4)-1
ti4(k) = interp1(y4([xi4(k) xi4(k)+1]), t([xi4(k) xi4(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end

回答(1 个)

darova
darova 2019-8-16
Then use for loop
% a(1) = 2;
% a(2) = 3;
% a(3) = 4;
% a(4) = 5;
for i = 1:4
a(i) = i+1;
end
Simple
  2 个评论
Ali Asghar
Ali Asghar 2019-8-21
dear
kindly suggest complete code.
like
or i = 1:4
a(i) = i+1;
y(i) = filter_datawindow(:,i) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
x(i) = zci(y(i)); % zero crossing indices command
for k = 1:numel(x(i))-1
ti1(k) = interp1(y(i)([x(i)(k) x(i)(k)+1]), t([x(i)(k) x(i)(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
end
this give error
darova
darova 2019-8-21
It's because you trying to assign
x(i) = [1 2 3];
You don't need indexes in this case
y = filter_datawindow(:,i) ; % filtered signal

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Filter Design and Analysis 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by