Numerical output from "fit" function using a loop
13 views (last 30 days)
Show older comments
Hello folks,
I have a matrix of water velocity data called ur10 (43x609), where there are 609 profiles at regular time intervals and 43 vertical depth bins per profile. I want to fit an exponential curve to the lowermost 4 bins of each profile, then pull out the coefficients (i.e. slope and y-intercept, here ustar and z0) of each line. My end goal is then to have two vectors, each 609 long, with all the slopes and y-intercepts. My code is below, but when I run it I get an error stating "Error using cfit/subsref. Too many output arguments." What do I need to change? I haven't used the "fit" function before so any advice would be much appreciated. I am using Matlab R2016b on a Macbook Pro. Thanks!
fitcoeffs=zeros(609,2);z0=zeros(609,1);ustar=zeros(609,1);
for i=1:609 %first 609 profiles go to z bin 41
%calculate ustar using lowest 4 z bins
[fit,gfit]=fit(ur10(38:41,i),z(38:41),'exp1');
fitcoeffs(i)=coeffvalues(fit);
z0(i)=fitcoeffs(i,1);
ustar(i)=fitcoeffs(i,2);
end
Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!