Tic and Toc Function

1 vue (au cours des 30 derniers jours)
Amanda Wojcik
Amanda Wojcik le 29 Oct 2017
Commenté : Amanda Wojcik le 29 Oct 2017
For my engineering class I had to make a while loop to find the average of a data set and use tic/toc to time the process. My code is posted below but for some reason when I run tic/toc it says it takes 7 seconds. I'm just not sure this is right because a few of my classmates told me theirs was around 1 second and when I time it myself it doesn't take 7 seconds. If someone could tell me where my error is if there is one I would appreciate it!
  4 commentaires
Walter Roberson
Walter Roberson le 29 Oct 2017
Modifié(e) : Walter Roberson le 29 Oct 2017
You have not given us any information about what Average does.
You could improve your performance by calculating length(y) once before the loop and using that variable. With your current code it needs to recalculate length(y) every step.
Amanda Wojcik
Amanda Wojcik le 29 Oct 2017
Ok thank you that makes sense! When I copied the code I forgot to include average=sum/length(y)

Connectez-vous pour commenter.

Réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by