how to speed my code up
1 view (last 30 days)
Here, line 4 and 5 is called 5525575680 times and they last 280 and 230 seconds in order. May I speed it up, how can I use it more efficient ?
1 function [utilization] = totalUtilization(myArray, periodNumber, count, LPP)
2 duration = 0;
3 for i = 1:count
4 duration = duration + myArray(periodNumber, i);
6 utilization = duration / LPP;
Thanks in advance.
Daniel M on 16 Nov 2019
Edited: Daniel M on 16 Nov 2019
Why do you need a loop to compute a sum? Just replace the entire function with
utilization = sum(myArray(periodNumber, 1:count)) / LPP;
And if count is equal to the number of columns of myArray, replace "1:count" with just ":" to avoid making an extra temporary index.
If periodNumber happens to be a vector, then include the number 2 as the dimension input into sum.