How do I preallocate this variable so that I can remove my warning and test whether my while loops are infinite or whether my code is just computing really slowly?

1 Ansicht (letzte 30 Tage)
I only have these variables left to "fix" and then my code will be "green", free from any errors or any warnings, but I do not know how to preallocate this variable, which I'm getting a warning of "The variable result appears to change for every loop iteration" for:
result(i+1,1)=phi;
result(i+1,2)=T_AF;
Currently, my code execution is just taking forever to finish and I'm not sure if it's my while loops or if it's not pre allocating the aforementioned variables,
My for loop is:
for i = 0:1:15
Thank you for your help!

Akzeptierte Antwort

Stephen23
Stephen23 am 9 Okt. 2020
Bearbeitet: Stephen23 am 9 Okt. 2020
result = nan(16,2); % preallocate
for ...
  2 Kommentare
Syed Awais
Syed Awais am 9 Okt. 2020
Thank you so much for the quick reply!
Yeah something's wrong with my code, this hasn't made a difference :( Still taking infinitely long
Ameer Hamza
Ameer Hamza am 9 Okt. 2020
@Syed, preallocation of just 32 elements isn't such a significant speed issue. The likely cause is your algorithm.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by