how to generate loop for given program

2 visualizaciones (últimos 30 días)
Ali Asghar
Ali Asghar el 16 de Ag. de 2019
Comentada: darova el 21 de Ag. de 2019
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

Respuestas (1)

darova
darova el 16 de Ag. de 2019
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 comentarios
Ali Asghar
Ali Asghar el 21 de Ag. de 2019
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 el 21 de Ag. de 2019
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

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by