How to fit an exponential curve? error: Dimensions of arrays being concatenated are not consistent
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have an energy plot that I would like to fit an exponential curve to.
I have something like this
numSteps = 5000;
x = 0:1:100;
time = zeros(1,numSteps+1);
ex_data = zeros(length(x),numSteps+1);
ex_data(:,1) = ex;
E_f = zeros(1, numSteps+1);
E_f(1) = 0.5*sum(ex.^2);
for i = 1:numSteps
%some calculations
[ex] = func(..) % ex calculated through some function
time(i+1) = (i)*dt;
E_f(i+1) = 0.5*sum(ex.^2 ) ;
end
%plot
figure(1)
s = fittype('a-b*exp(-c*x)');
f = fit(time, E_f, s, 'StartPoint', [[ones(size(time)), -exp(-time)]\E_f; 1]);
xx = linspace(0,50,250);
plot(time, E_f, 'o', xx, f(xx), 'r-');
grid on
title('Electric Field Energy')
I am trying to fit an exponential to this plot from xlim([ 0 80]) but I am getting the error
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in WeakBeam (line 184)
f = fit(time, E_f, s, 'StartPoint', [[ones(size(time)), -exp(-time)]\E_f; 1]);
I will post the entire code with functions if needed, thank you.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Fit Postprocessing 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!