Using while loop to determine average
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
student187
el 18 de Oct. de 2015
Comentada: Khalid Ghwani
el 3 de Abr. de 2021
I need to calculate the average using a while loop only. The first step is to add up all my vectors into one number. This is what I've done so far.
fid = fopen('Watts.dat');
r1 = fscanf(fid,'%f');
stop = 0;
sumx = 0;
n = 1;
while (stop <= 31)
f = r1(n)
sumx = r1(f) + sumx;
stop = stop +1;
n = n+1
end
However, I get the message
Attempted to access r1(2005.6); index must be a positive integer or logical.
I can't round these numbers. Do you guys have any suggestions?
1 comentario
Khalid Ghwani
el 3 de Abr. de 2021
Use a while loop to write a Matlab program to find the average any set of numbers entered by the user (not of known size)
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!