您可以尝试使用interp1函数。我知道下采样本身并不是真正的插值。这里有一个例子:
x1 = [0:0.1:pi];%vector length is 32
x2 = [0:0.01:pi];% vector length is 315
y1 = sin(x1);
y2 = sin(x2);
%down sample y2 to be same length as y1
y3 = interp1(x2,y2,x1);%y3 length is 32
figure(1)
plot(x2,y2);
hold on
plot(x1,y1,'k^');
plot(x1,y3,'rs');
% in general use this method to down-sample (or up-sample) any vector:
% resampled = interp1(current_grid,current_vector,desired_grid);
% where the desired_grid is a monotonically increasing vector of the desired length
% For example:
x5 = [0.0:0.001:1-0.001];
y5 = sin(x);
% If I want to down sample y5 to be 100 data points instead of 1000:
y6 = interp1([1:length(y5)],y5,1:1:100);
% y6 is now 100 data point long. Notice I didn't use any other data except for y6, the length of y6 and my desired length.
好的,这是否意味着我是正确的说这个问题不能用resample函数解决? –
好吧,我刚刚试过你说的,我得到了这个错误: “网格向量不是单调递增的。” 这种方法是否假定两个向量是相似的函数?他们不在我的情况。我很抱歉,如果我应该指出这一点。 –
好的,对不起,我编辑了我的答案以包含更好的解释。这两个向量是不同的功能并不重要。您看到的错误很可能是因为您为“x”或网格变量输入了错误的输入。再请参阅我的答案以获取更多示例。 – willpower2727