Can't save values to array with for loop
1 view (last 30 days)
Show older comments
Caleb Nickens
on 29 Jan 2021
Commented: Caleb Nickens
on 29 Jan 2021
function traprule = traps(fr,y,a,b)
format long
dx = (1/fr); % fr = frequency in Hz
N = ((b + a)/dx) + 1; % creating N trapezoids to match number of time intervals
x = a +[0:N - 1]*dx;
if abs(b - a) < eps | N <= 0, traprule = 0;
return
end
w = [ 0.5 ones(1,N-2) 0.5 ]; % w = weight
for i = 1 : N
Int(i) = (w(i).*y(i))*dx; %calculates integral
end
I = 0;
for j = 1 : N
I = I + Int(j);
disp(I)
end
This function is meant to integrate acceleration vs time data to obtain velocity vs time data. I want to save "I" values in the final for loop to a table or array but do not know how to achieve this. Is there a simpler method?
0 Comments
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!