Effacer les filtres
Effacer les filtres

Can't save values to array with for loop

1 vue (au cours des 30 derniers jours)
Caleb Nickens
Caleb Nickens le 29 Jan 2021
Commenté : Caleb Nickens le 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?

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Jan 2021
for j = 1 : N
I = I + Int(j);
disp(I)
all_I(j) = I;
end
  1 commentaire
Caleb Nickens
Caleb Nickens le 29 Jan 2021
Thank you for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by