Hey,
can i just plot the smoothing line without the scatter points? And is it possible to get just the Data of the smoothing line to plot more than one line in one figure?
Thank you!

댓글 수: 1

Cameron
Cameron 2023년 1월 2일
What do you mean by smoothing line? You can take the information from polyfit and use that if it's some polynomial fit, but I'm not sure what your model looks like. I'm also not sure what the second question means.

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

 채택된 답변

Star Strider
Star Strider 2023년 1월 2일

1 개 추천

I am not certain what you wnat to do.
Taking a guess —
N = 20;
x = sort(randn(1,N));
y = randn(1,N);
xs = linspace(min(x), max(x), 10*N);
ys = interp1(x, y, xs, 'spline'); % Interpolate Using 'spline'
figure
subplot(2,1,1)
plot(x, y, '.')
hold on
plot(xs, ys)
hold off
grid
axis('padded')
title('With Points')
subplot(2,1,2)
plot(xs, ys)
grid
axis('padded')
title('Without Points')
To plot more than one line in one axes, use the hold function. To plot more than one axes in one figure, use subplot, tiledlayout, or stackedplot, depending on what you want to do. (I have illustrated a version all those here.)
.

댓글 수: 5

Max1234
Max1234 2023년 1월 3일
Thank you very much for your efforts.
Your answer already goes in the right direction. I have several data sets that have a large number of measuring points. I would like to generate a trend line from all six data sets and display it in a diagram. In this diagram, only the trend lines and not the points should be visible. Unfortunately, with the Curve Fit Tool only one curve is possible at a time and the scatter points are visible.
I have tried your answer, but I always get errors. As X-values I have converted dates into numbers with datenum.
Thanks again for the help!
Max1234
Max1234 2023년 1월 3일
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in Skript02 (line 67)
ys1 = interp1(x,y,xs1,'spline');
This is the errormessage....
My pleasure!
I was not certain what you meant by ‘smoothing line’.
To calculate a linear regression for all the points, the correct approach would be to use the polyfit and polyval functions —
N = 20;
x = randn(1,N);
y = randn(1,N);
xs = linspace(min(x), max(x), 10*N);
b = polyfit(x,y,1);
ys = polyval(b, xs);
figure
subplot(2,1,1)
plot(x, y, '.')
hold on
plot(xs, ys)
hold off
grid
axis('padded')
title('With Points')
subplot(2,1,2)
plot(xs, ys)
ylim([min(y) max(y)])
grid
% axis('padded')
title('Without Points')
The polyfit function can also fit polynomials of integer degrees greater than 1.
.
Max1234
Max1234 2023년 1월 3일
Thank you very much! You helped me a lot!
Star Strider
Star Strider 2023년 1월 3일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Smoothing에 대해 자세히 알아보기

질문:

2023년 1월 2일

댓글:

2023년 1월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by