Filter löschen
Filter löschen

Can't save values to array with for loop

1 Ansicht (letzte 30 Tage)
Caleb Nickens
Caleb Nickens am 29 Jan. 2021
Kommentiert: Caleb Nickens am 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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Jan. 2021
for j = 1 : N
I = I + Int(j);
disp(I)
all_I(j) = I;
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by