how to use spline for a fig. file?

1 回表示 (過去 30 日間)
Sajid Sarwar
Sajid Sarwar 2019 年 7 月 3 日
コメント済み: Sajid Sarwar 2019 年 7 月 3 日
Can I use spline to smooth the plot in attached file?

採用された回答

Star Strider
Star Strider 2019 年 7 月 3 日
編集済み: Star Strider 2019 年 7 月 3 日
Try this:
I = openfig('fft scma 25.fig');
Ax = gca;
lgnd = Ax.Legend;
Lines = findobj(Ax,'Type','line');
N = 5; % Interpolation Points Length Multiplication
for k = 1:numel(Lines)
X(k,:) = Lines(k).XData;
Y(k,:) = Lines(k).YData;
xq(k,:) = linspace(min(X(k,:)),max(X(k,:)), numel(X(k,:))*N); % Interpolation Points Vector
ys(k,:) = spline(X(k,:),Y(k,:),xq(k,:)); % Spline Fit To Data
end
figure
semilogy(xq', ys')
grid
legend(Ax.Legend.String)
xlabel(Ax.XLabel.String)
ylabel(Ax.YLabel.String)
Change ‘N’ to get the result you want.
This is essentially the same as my previous code, this time doing a spline interpolation.
EDIT —
Corrected typographical error. Code unchanged.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 7 月 3 日
Ninterp = 10;
Nplot = 100;
fig = openfig('fft scma 25.fig');
Lines6to1 = findobj(fig, 'type', 'line');
for idx = 1 : length(Lines6to1)
h = Lines6to1(idx);
xd = get(h, 'XData');
yd = get(h, 'YData');
x = linspace(min(xd), max(xd), Ninterp);
y = interp1(xd, yd, x, 'spline');
xx = linspace(min(xd), max(xd), Nplot);
yy = spline(x, y, xx);
set(h, 'XData', xx, 'YData', yy);
end
  1 件のコメント
Sajid Sarwar
Sajid Sarwar 2019 年 7 月 3 日

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by