フィルターのクリア

Can't save values to array with for loop

1 回表示 (過去 30 日間)
Caleb Nickens
Caleb Nickens 2021 年 1 月 29 日
コメント済み: Caleb Nickens 2021 年 1 月 29 日
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?

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 29 日
for j = 1 : N
I = I + Int(j);
disp(I)
all_I(j) = I;
end
  1 件のコメント
Caleb Nickens
Caleb Nickens 2021 年 1 月 29 日
Thank you for your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by