# How to smoothen curves?

조회 수: 1 (최근 30일)
Elysi Cochin 2021년 6월 14일
답변: Image Analyst 2021년 6월 20일
I have attached my data values
I plot it using the below code
x = data(:,1);
y = data(:,2:end);
figure(2), plot(x, y, 'LineWidth', 2);
Without changing the 1st row, last row and 20th row of y-values, how to smoothen the data

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

### 채택된 답변

Image Analyst 2021년 6월 20일
Try this. Note the discontinuities at elements 1, 20, and 100 meaning the data was not changed for those elements. Change windowWidth to adjust the amount of smoothing.
x = data(:, 1); % x is in column 1
y = data(:, 2:end); % y is in columns 2 through 13.
nexttile;
plot(x, y,'-', 'LineWidth', 2);
grid on;
title('Original Data', 'FontSize', 20);
nexttile;
[rows, columns] = size(y)
windowWidth = 19; % Higher for more smoothing, smaller for less smoothing.
for col = 1 : columns
% y is in columns. Get the y in this column.
thisy = y(:, col);
% Smooth it.
ySmooth = movmean(thisy, windowWidth);
% Replace elements 1, 20, and end with the original values.
ySmooth([1, 20, rows]) = thisy([1, 20, rows]);
plot(x, ySmooth, '-', 'LineWidth', 2);
hold on;
end
grid on;
hold off;
g = gcf;
g.WindowState = 'maximized';
% Indicate element #20
yl = ylim
line([x(20), x(20)], [0.72, yl(end)], 'LineWidth', 2, 'Color', 'r');
text(x(20), 0.72, ' Element 20', 'FontSize', 20, 'FontWeight', 'bold', 'Color', 'r');
title('Smoothed Data', 'FontSize', 20);

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

### 추가 답변 (1개)

KSSV 2021년 6월 14일
x = data(:,1);
y = data(:,2:end);
figure(1),
plot(x, y,'r');
yi = zeros(size(y)) ;
for i = 1:size(y,2)
yi(:,i) = smooth(x,y(:,i)) ;
end
figure(2)
plot(x,yi,'k')
##### 댓글 수: 2없음 표시없음 숨기기
KSSV 2021년 6월 14일
Use indexing.. M
Image Analyst 2021년 6월 20일
How does this not change rows 1, 20, and the last row?

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

### 카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by