Failure in automating the cftool / a fourier series programmatically
Show older comments
I'm attempting to automate the process of fitting a fourier series to multiple x,y data by using the curve fitting tool functions. Because cftool requires the use of a column vector with one column, I have preallocated the x and y data and transposed them into column format. If the deadflag~=0, I want the code to skip the curve fitting and re-enter the loop.
Basically, I want seperate curve fits (i.e., indepedent functions, a, b, w parameter values and R^2 values) for 'k' number of columns of x and y. When I run the code, I don't get any errors, but the respective curve fitting data isn't created. Sorry in advance for my terrible coding- I'm a self-taught programming newbie. :/ Here's what I have so far:
%Preallocate x and y data
x_k=zeros(numcells,numdatapoints);
x_yes=1:numdatapoints;
x_no=zeros(1,numdatapoints);
for k=1:numcells-1
if deadflag(k)==0
x_k(k,:)=x_yes;
else
x_k(k,:)=x_no;
end
end
y_k=zeros(numcells,numdatapoints);
y_k(:,:)=ydata(:,:);
%Transpose x and y data into column vectors and rename
x_cv=x_k';
y_cv=y_k';
x=x_cv(:,k);
y=y_cv(:,k);
%Curve fitting loop
f8=fittype('fourier8');
f8fit=zeros(numdatapoints);
for k=1:numcells-1
if deadflag(k)==0
f8fit(k)=fit([x,y],f8);
else
break;
end
end
Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox 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!