Interpolate/Resample to a specific decimal point
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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))
0 个评论
更多回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!