recall Equation of fit curve and integrate
1 次查看(过去 30 天)
显示 更早的评论
I have set the curve fitting and know that "formula" finds me the equation of the line. I cant seem to figure out a way to jsut automatically set it equal to a variable without manually typing "formula(linefit)" and pasting the actual equation into my code. I tried "accelformula= formula(linefit)" which works, but the moemnt I try "vformula=int(accelformula)" mat lab give me an error.
clc
clear all
close all
figure(1)
accel1=readtable('accelplot1','PreserveVariableNames',true);
a=1550;
b=1850;
time=accel1{a:b,1};
ay=accel1{a:b,7};
%xlim([8.75 11.25])
linefit=fit(time,ay,'sin2');
%plot(linefit,time,ay)
yfitted = feval(linefit,time);
subplot(2,2,1)
plot(time,ay,'b',time,yfitted,'r')
title('Accelorometer data')
xlabel('time(sec)')
ylabel('acceleration(in/sec^2')
%% acceleration to displacement
a1=linefit.a1;
b1=linefit.b1;
c1=linefit.c1;
a2=linefit.a2;
b2=linefit.b2;
c2=linefit.c2;
syms x
accelformula= formula(linefit)
velformula=int(a1*sin(b1*x+c1) + a2*sin(b2*x+c2))
vformula=int(accelformula)
subplot(2,2,2)
w=min(time):max(time)
fplot(velformula,w)
title('Velocity')
xlabel('time(sec)')
ylabel('Velocity(in/sec)')
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!