How reduce data from 3917x2 to 1868x2 without change the entire of graph?

1 回表示 (過去 30 日間)
I have zdata.mat contains data 3917x2 I need a way to reduce data to 1868x2 , (hint: first column refers to x axis, second column refers to y axis)

採用された回答

John D'Errico
John D'Errico 2024 年 8 月 23 日
編集済み: John D'Errico 2024 年 8 月 23 日
Just take every other data point, if you just want to roughly reduce the size. But you say you want a specific length. So then you would need to interpolate.
load zdata.mat
plot(z(:,1),z(:,2),'-')
x = z(:,1); y = z(:,2);
xnew = linspace(min(x),max(x),1868);
ynew = interp1(x,y,xnew);
length(ynew)
ans = 1868
plot(xnew,ynew,'-')
Finally, if you want to do some smoothing, you might try something like:
ysmooth = smooth(x,y);
ynewsmooth = interp1(x,ysmooth,xnew);
plot(xnew,ynewsmooth,'-')
And depending on the smoothing method you choose, you can adjust the amount of smoothing done. You could also use a smoothing spline. Something like this (fit requires the curve fitting toolbox.)
spl = fit(x,y,'smoothingspline');
ynewspl = spl(xnew);
plot(xnew,ynewspl,'-')
Remember that when you have a sharp spike as this curve shows, anything you do to downsample such a curve may miss exactly where that spike happens, and how far it extends. But that is a given. If you reduce the sampling frequency, then you also reduce the information content of your data.
  3 件のコメント
John D'Errico
John D'Errico 2024 年 8 月 23 日
Note that interp1 makes no presumption of a uniform stride between data points. This is also the case for fit, which does not give a hoot about uniformity of stride. Finally, while SOME of the methods offered in smooth do care, not all of them do.
Walter Roberson
Walter Roberson 2024 年 8 月 23 日
My note about the differences was after your original answer, but before you did the interpolation.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by