How to smoothen the curve in Matlab, preserving the original data points at a acceptable level?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ans
am 2 Nov. 2021
Beantwortet: Star Strider
am 2 Nov. 2021
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")''
0 Kommentare
Akzeptierte Antwort
Star Strider
am 2 Nov. 2021
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!