How to improve speed ?
Show older comments
I have this code :
for alfa1=0.005:.00005:0.03
(.....)
p=round(max(size(z))/4);
soln1=z(:,1);
soln1=soln1(end-p:end);
soln2=z(:,2);
soln2=soln2(end-p:end);
soln3=z(:,3);
soln3=soln3(end-p:end);
soln4=z(:,4);
soln4=soln4(end-p:end);
s1(dim)=max(soln1);
s2(dim)=min(soln1);
i1(dim)=max(soln2);
i2(dim)=min(soln2);
p1(dim)=max(soln3);
p2(dim)=min(soln3);
q1(dim)=max(soln4);
q2(dim)=min(soln4);
A(dim)=alfa1;
dim=dim+1;
count=count+1;
end
So i have this code , and it literally takes minutes to run , i wonder if someone can help me , i dont know how to preallocate the variables , in order to improve speed.
1 Comment
Stephen23
on 5 Dec 2018
"How to improve speed ?"
By following the guidelines in the MATLAB documentation:
Answers (1)
A = 0.005:0.00005:0.03;
N = numel(A);
M1 = nan(N,4); % max
M2 = nan(N,4); % min
for k = 1:N
...
p = round(max(size(z))/4);
m = z(end-p:end,1:4);
M1(k,:) = max(m,[],1);
M2(k,:) = min(m,[],1);
end
Whether this is really the bottleneck in your code is another matter entirely... have you profiled your code?
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!