Can't save values to array with for loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!