need help with array resizing

2 次查看(过去 30 天)
sudipta
sudipta 2017-1-28
编辑: Jan 2017-1-28
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 个评论
Jan
Jan 2017-1-28
Please use the "{} code" button to format your code. Thanks. I've done this for you this time.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2017-1-28
编辑:Jan 2017-1-28
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

类别

Help CenterFile Exchange 中查找有关 Detection, Range and Doppler Estimation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by