Optimization of code with double for-loops
Ältere Kommentare anzeigen
I am looking to optimize the following code specifically, and more generally, I am trying to learn optimization techniques in MATLAB for a larger project. The code below is just a snippet example which I am looking to learn techniques and then apply to a larger problem. I am potentially looking at values of L being as high as
with four nested loops as opposed to just the two shown below.
Any pointers (or links to decent YouTube video on MATLAB optimization) would be welcomed.
clc; clearvars;
T = 1; Ts = 1e-2; t = 0:Ts:L*T;
L = 2^5;
start_time = clock();
for l = 0:L-1
for q = 0:L-1
flag = (t>=(l-q-1)*T) & (t<=(l-q+1)*T);
partA = (T-abs(t-(l-q)*T));
end
end
elapsed_time = clock();
time = elapsed_time(4)*3600+elapsed_time(5)*60+elapsed_time(6)
4 Kommentare
Walter Roberson
am 20 Nov. 2022
for q = 0:L-1
flag = (t>=(l-q-1)*T) & (t<=(l-q+1)*T);
Catalytic
am 20 Nov. 2022
@Howard Wilton You appear to have opened several previous threads on similar subjects to this and abandoned them, without accepting an answer or follow-up discussion. It is better if you not do this, so that contributors can know if the question is to be taken seriously.
Howard Wilton
am 20 Nov. 2022
Howard Wilton
am 20 Nov. 2022
Bearbeitet: Howard Wilton
am 20 Nov. 2022
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!