Borrar filtros
Borrar filtros

need help with array resizing

2 visualizaciones (últimos 30 días)
sudipta
sudipta el 28 de En. de 2017
Editada: Jan el 28 de En. de 2017
I am attaching one mat file with my data array. It is a current pulse recorded for negative , positive and zero bias condition. I am trying to resize the collected data by eliminating all values near to zero. I am using the below code for finding slope between every 3 data points and when slope is above certain value detecting that index and select next 60 data points inside loop. But there is some error which I am unable to figure out; causing multiple writing of the selected region. I think I am not able to explain it properly.Here is the code;
k=1;
for i=1:10000
D(k) = (A1(i+2,2)-A1(i,2))/(A1(i+2,1)-A1(i,1));
if abs(D(k))>500
B1(:,k) = A1(i:i+59,2);
T1(:,k) = A1(i:i+59,1);
k=k+1;
end
end
plot(T1,B1,'o-')
Thanks for help.
  1 comentario
Jan
Jan el 28 de En. de 2017
Please use the "{} code" button to format your code. Thanks. I've done this for you this time.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 28 de En. de 2017
Editada: Jan el 28 de En. de 2017
A solution with minimal changes:
k = 1;
i = 1;
while i < 9941 % 10000 - 59 because A(i+59, :) is accessed
D = (A1(i+2,2)-A1(i,2))/(A1(i+2,1)-A1(i,1)); % Is D needed outside?
if abs(D) > 500
B1(:,k) = A1(i:i+59,2);
T1(:,k) = A1(i:i+59,1);
k = k + 1;
i = i + 60; % Exclude the next 59 elements
else
i = i + 1
end
end
plot(T1,B1,'o-');
This will be more efficient:
D = (A1(3:end, 2) - A1(1:end-2, 2)) ./ (A1(3:end, 1) - A2(1:end-2, 1));
match = find(abs(D > 500));
B1 = zeros(60, numel(match)); % Pre-allocate
T1 = zeros(60, numel(match)); % Pre-allocate
for k = 1:numel(match)
idx = match(k);
T1(:, k) = A1(idx:idx+59, 1);
B1(:, k) = A1(idx:idx+59, 2);
end

Categorías

Más información sobre Detection, Range and Doppler Estimation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by