how to generate loop for given program

1 回表示 (過去 30 日間)
Ali Asghar
Ali Asghar 2019 年 8 月 16 日
コメント済み: darova 2019 年 8 月 21 日
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 Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by