Preallocated array A using a for loop

3 vues (au cours des 30 derniers jours)
timetry2
timetry2 le 15 Sep 2019
Commenté : madhan ravi le 15 Sep 2019
Consider an iterative series 1, (-1)/2, 1/3, (-1)/4, 1/5,…(-1)^(k-1)/k. The first 5 terms for k=1:5 are written here. Create the first 100 and store them all in a preallocated array A using a for loop.
Please help with this question. Thanks in advance!

Réponse acceptée

madhan ravi
madhan ravi le 15 Sep 2019
https://in.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html - you will see how to store values in each iteration through preallocation.
  8 commentaires
timetry2
timetry2 le 15 Sep 2019
One last thing, what are the tic toc functions doing then? I've only learned about for and while loops. And, I was curious how this function works without incorporating either. Thank you so much for the help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming 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