
how can I smooth the graph for a set of varying data points??
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Shahriar Shafin
 el 30 de Nov. de 2023
  
    
    
    
    
    Comentada: Mathieu NOE
      
 el 30 de Nov. de 2023
            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 :

0 comentarios
Respuesta aceptada
  Mathieu NOE
      
 el 30 de Nov. de 2023
        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 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Interpolation en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!