필터 지우기
필터 지우기

How to fit an exponential curve? error: Dimensions of arrays being concatenated are not consistent

조회 수: 2 (최근 30일)
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.

답변 (1개)

Matt J
Matt J 2021년 3월 3일
편집: Matt J 2021년 3월 3일
Did you mean,
[[ones(size(time)); -exp(-time)].\E_f; ones(size(time))]
  댓글 수: 2
Jamie Al
Jamie Al 2021년 3월 3일
Hmm I am getting this error now:
Error using fit>iFit (line 135)
X must be a matrix with one or two columns.
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in WeakBeam (line 223)
f = fit(time, E_f, s, 'StartPoint',[[ones(size(time)); -exp(-time)].\E_f; ones(size(time))]);
Matt J
Matt J 2021년 3월 3일
편집: Matt J 2021년 3월 3일
time , E_f, s must all be column vectors. It looks like you made them row vectors. Also, make sure that that complicated looking calculation of your StartPoint really results in a vector of 3 parameters.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by