필터 지우기
필터 지우기

how can I smooth the graph for a set of varying data points??

조회 수: 1 (최근 30일)
Shahriar Shafin
Shahriar Shafin 2023년 11월 30일
댓글: Mathieu NOE 2023년 11월 30일
How can I make the graph more smooth and equlibriate perfectly with the upper graph like the right one in MATLAB??
data sets are given below :

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 11월 30일
hello
maybe this ? (I optd for a exponential fit of your lattice data)
data1 = readmatrix('lattice vs time plot.xlsx');
x1 = data1(:,1);
y1 = data1(:,2);
data2 = readmatrix('electron vs time plot.xlsx');
x2 = data2(:,1);
y2 = data2(:,2);
[k, yInf, y0, yFit] = fitExponential(x1, y1);
figure(1);
plot(x1,y1,'g',x2,y2,'r','linewidth',2);
hold on
plot(x1,yFit,'k','linewidth',5);
hold off
% apply corrective factor on fitted curve to math the other curve asymptote
y2_asymp = mean(y2(round(end/2):end));
correction_factor = y2_asymp/yFit(end);
yFit = yFit*correction_factor;
figure(2);
plot(x1,y1,'g',x2,y2,'r','linewidth',2);
hold on
plot(x1,yFit,'k','linewidth',5);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [k, yInf, y0, yFit] = fitExponential(x, y)
% FITEXPONENTIAL fits a time series to a single exponential curve.
% [k, yInf, y0] = fitExponential(x, y)
%
% The fitted curve reads: yFit = yInf + (y0-yInf) * exp(-k*(x-x0)).
% Here yInf is the fitted steady state value, y0 is the fitted initial
% value, and k is the fitted rate constant for the decay. Least mean square
% fit is used in the estimation of the parameters.
%
% Outputs:
% * k: Relaxation rate
% * yInf: Final steady state
% * y0: Initial state
% * yFit: Fitted time series
%
% improve accuracy by subtracting large baseline
yBase = y(1);
y = y - y(1);
fh_objective = @(param) norm(param(2)+(param(3)-param(2))*exp(-param(1)*(x-x(1))) - y, 2);
initGuess(1) = -(y(2)-y(1))/(x(2)-x(1))/(y(1)-y(end));
initGuess(2) = y(end);
initGuess(3) = y(1);
param = fminsearch(fh_objective,initGuess);
k = param(1);
yInf = param(2) + yBase;
y0 = param(3) + yBase;
yFit = yInf + (y0-yInf) * exp(-k*(x-x(1)));
end
  댓글 수: 4
Shahriar Shafin
Shahriar Shafin 2023년 11월 30일
@Mathieu NOE got it,thanks .Saved my day.
Mathieu NOE
Mathieu NOE 2023년 11월 30일
ok
glad I could be of some help !

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by