How to smoothen the curve in Matlab, preserving the original data points at a acceptable level?
조회 수: 21 (최근 30일)
이전 댓글 표시
Hello! I am aware that there have been so many questions regarding "how to smoothen the curve", which have been explicitly answered in Mathworks community. What I am trying to do is that I would like to draw a linear line from the origin and offset it up to 0.2% to find the yielding point. To draw the linear line, I have used the linear least square fitting method to find the slope (m), considering the y intercept (C) is zero since it is suposed to intercept the origin point (0,0). Utilizing the value of slope, I have drawn the linear line as mentioned in the following images, but it does not seem the result is at the acceptable level once zoomed in. In my opinion, it might be due to two factors. The first might be correlated with the fact that I want the intersect of Yaxis to be zero and the latter should be the irregularities of the linear region of the curve. If possible, I want to adjust the linear region and entire curve. As a result, I have tried different Matlab functions like "smooth","spline","interpolation", but the result are not still at satisfied level. Once I use "smooth function", the irregularities of the curve can be minimized, but at the expense of the original data. Please let me kow your ideas and guidelines.
clc
clear
close all
M = readtable('red_0.01.csv');
T = table2array(M);
X = T(:,1);
Y = T(:,2);
X = (X-min(X)); % This is excuted in order to correct the X axis and set 0 as original point.
Y = (Y-min(Y)); % This is excuted in order to correct the Y axis and set 0 as original point.
[UTS,idx] = max(Y); % Ultimate tensile strength (UTS).
strain_UTS = X(idx); % strain at UTS.
xlinear = X(X<0.009);
ylinear = interp1(X,Y,xlinear,"spline","extrap")
% ylinear = Y(X<0.009);
p = lsqlin(xlinear,ylinear)
slope_m = p;
elastic_y = slope_m*xlinear
figure ()
plot(X,Y,"b-","LineWidth",2);
hold on
plot(xlinear,ylinear,"ko")
plot(xlinear,elastic_y,"r-","LineWidth",1.5)
% To smooth the whole curve, I have tried as follow.
X_1 = linspace(X(1),X(end),500);
Y_1 = interp1(X,Y,X_1,"spline","extrap")''
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/787145/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/787150/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/787155/image.jpeg)
댓글 수: 0
채택된 답변
Star Strider
2021년 11월 2일
I am not certain what the desired result is. It is straightforward to force a curve to have a zero intercept, although the code for it must be written specifically for that purpose.
See if this works —
M = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/787120/red_0.01.csv');
% T = table2array(M);
X = M{:,1};
Y = M{:,2};
X = (X-min(X)); % This is excuted in order to correct the X axis and set 0 as original point.
Y = (Y-min(Y)); % This is excuted in order to correct the Y axis and set 0 as original point.
[UTS,idx] = max(Y); % Ultimate tensile strength (UTS).
strain_UTS = X(idx); % strain at UTS.
xlinidx = (X<0.009);
% ylinear = interp1(X,Y,xlinear,"spline","extrap")
% ylinear = Y(X<0.009);
% p = lsqlin(xlinear,ylinear)
p = X(xlinidx) \ Y(xlinidx) % Forces Zero Intercept
slope_m = p;
% elastic_y = slope_m*xlinear
figure ()
plot(X,Y,"b-","LineWidth",2);
hold on
% plot(xlinear,ylinear,"ko")
% plot(xlinear,elastic_y,"r-","LineWidth",1.5)
plot(X(xlinidx), p*X(xlinidx), '-r')
% To smooth the whole curve, I have tried as follow.
X_1 = linspace(X(1),X(end),500);
Y_1 = interp1(X,Y,X_1,"spline","extrap");
figure
plot(X,Y,"b-","LineWidth",2)
hold on
plot(X(xlinidx), p*X(xlinidx), '-r')
hold off
grid
xlim([0 0.01])
.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!