How to calculate acceleration between two cells from data using for...end
2 views (last 30 days)
Show older comments
I'm really new to MatLab and my programming moduel uses it. My task is to calculate accleration between two cells using the for loop command. this is my code so far but it doesnt work. Please help.
x=ev_data.Time; %time in seconds [Time]
y=ev_data.Speed;
ii=1;
for i=ev_data.Time
y1(ii)=(((ev_data.Speed+1)-ev_data.Speed)/ev_data.Time);
ii=ii+1;
end
figure;
plot(x,y1);
hold on;
plot(x,y)
legend('derivate approximated','sin(x)')
0 Comments
Answers (1)
Anmol Dhiman
on 8 Apr 2020
Hi Favour,
I am assuming x and y are vectors(arrays). For each time interval you are calculating acceleration(y11). YOu can follow the below code
x=ev_data.Time; %time in seconds [Time]
y=ev_data.Speed;
for i=1:ev_data.Time
y1(i)=(((y(i)+1)-y(i))/x(i));
end
figure;
plot(x,y1);
hold on;
plot(x,y);
legend('derivate approximated','sin(x)') ;
Hope it helps
Thanks,
Anmol Dhiman
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!