필터 지우기
필터 지우기

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