keepdata.m
来自「uses partial correlation function and fi」· M 代码 · 共 37 行
M
37 行
function [ti,xi] = keepdata(x,p)
%
% Keeps arbitrary fraction p of equidistant data x at times ti.
% Output contains data xi at time ti
if p > 1, error('p must be between 0 and 1'), end
N=length(x);
Nover=floor(p.*N);
% over is the array of remaining points with value 1
over=zeros(1,N);
ti=zeros(1,Nover);
xi=zeros(1,Nover);
% Select at random Nover points
i = 0;
while (i < Nover)
r = rand(1);
k = round((N - 1) .* r) + 1;
if (over(k) ~= 1)
over(k) = 1;
i = i + 1;
end
end
% Generate output data
j = 1;
for i=1:N
if (over(i) == 1)
xi(j) = x(i);
ti(j) = i;
j = j + 1;
end
end
fprintf('Over: %d\n', j-1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?