Interpolate/Resample to a specific decimal point

조회 수: 14 (최근 30일)
Anmol Jarang
Anmol Jarang 2021년 9월 21일
댓글: Anmol Jarang 2021년 9월 21일
I've got a cell array with different values in each array, sampled at different points. These points are random. I'm currently trying to figure out a way to resample+interpolate them in such a way that I can average over each cell row in the cell array. for example,
x{2}=[1 3 4 7 6 3 6]
should become
x{2}=[1 2 3 4 5 6 7 6 5 4 3 4 5 6]
I've looked into functions like interp1 and resample, but these assume that you have a vector of points you want to get or the target number of samples. I know neither. The ideal function would be something that takes in the intial vector(x{2}) and the desired sampling interval (1). How can I go about solving this problem?
  댓글 수: 2
Matt J
Matt J 2021년 9월 21일
편집: Matt J 2021년 9월 21일
Suppose your sampling interval was 1, but your initial vector was
x=[1 3.17 4 7.8 6 3 6]
What result would you expect?
Or, what if your input vector was still
x=[1 3 4 7 6 3 6]
but your sampling interval was 1.6? What result would you expect then?
Anmol Jarang
Anmol Jarang 2021년 9월 21일
I should've added this in the post, but my data will always have the same number of digits after the decimal point. For the first one, I would have 2 digits after the decimal point, so my sampling interval would be .01, and I'd have a vector that would be [1 1.01 1.02 .... 3.17 3.18....].

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2021년 9월 21일
Assuming no adjacent duplicate values:
S = 1;
V = [1,3,4,7,6,3,6];
X = cumsum([1,abs(diff(V))]);
Z = interp1(X,V,1:S:X(end))
Z = 1×14
1 2 3 4 5 6 7 6 5 4 3 4 5 6

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 9월 21일
hello
try this :
x=[1 3 4 7 6 3 6];
out = my_resample(x)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out = my_resample(x)
out = [];
for ci = 2:length(x)
delta = sign(x(ci) - x(ci-1));
tmp = x(ci-1):delta:x(ci);
out = [out tmp(1:end-1)];
end
out = [out x(end)]; % include last value
end
it gives :
out = 1 2 3 4 5 6 7 6 5 4 3 4 5 6

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by