need help with array resizing
4 ビュー (過去 30 日間)
古いコメントを表示
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
2017 年 1 月 28 日
Please use the "{} code" button to format your code. Thanks. I've done this for you this time.
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File 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!