Increasing Speed of Execution
4 views (last 30 days)
Show older comments
Jacob Rensner
on 11 Apr 2019
Commented: Jacob Rensner
on 11 Apr 2019
The code below analyzes the slope of a dataset. We know that the graph of this dataset has a very distinct point where the slope begins rising much faster. To identify this point in MATLAB, we have written the follwoing code...
Deviation = zeros(length(Temperature), 1);
for i = 1:length(Temperature)
Temperature_Avg = sum(Temperature(1:i))/i;
Deviation(i) = (Temperature(i) - Temperature_Avg)^2;
end
Avg_Slope = zeros(length(Deviation)/5, 1);
for j = 1:5:length(Deviation)
Avg_Slope(j + 4) = (sum(Deviation(j:1:(j + 4)))) / 5;
end
n = 1;
Partial_Avg_Slope = Avg_Slope(5) / n;
Run_Avg_Slope = sum(Avg_Slope(1:1:(5 * n))) / n;
while Partial_Avg_Slope <= (4 * Run_Avg_Slope)
n = n + 1;
Run_Avg_Slope = sum(Avg_Slope(1:1:(5 * n))) / n;
Partial_Avg_Slope = Avg_Slope(5 * n);
end
t_s = Time((n * 5), 1);
if Temperature(end) > Temperature(1) % Parameter for heating system
y_L = sum(Temperature(1:1:(n * 5)))/(n * 5);
elseif Temperature(end) < Temperature(1) % Parameter for cooling system
y_H = sum(Temperature(1:1:(n * 5)))/(n * 5);
end
The code achieves it's goal but it is very slow, especially since it has to be executed for 100 datasets. Most of that run time comes from the line that caluclates Temperature_Avg. Is there any way that that line can be written so that it runs faster? Temperature and Time are row vectors with 10240 entries.
0 Comments
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!