recall Equation of fit curve and integrate

조회 수: 1 (최근 30일)
Darren Marcelino
Darren Marcelino 2023년 1월 20일
답변: Torsten 2023년 1월 20일
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)')

답변 (1개)

Torsten
Torsten 2023년 1월 20일

카테고리

Help CenterFile 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!

Translated by