How to effectively run loops and save time in computation? I have a matrix of size 'm' and run five loops from 1 to m.. How to optimize the code and save time of calculation for the code below
Show older comments
Can you help in optimizing the code below so that the execution time can be reduced? For a very large matrix of size 500x500, the computation time is huge. How to reduce it?
Since floor function is used here, is there any way to effectively compute the below code with both Time and Space efficiency..
function [PS] = PS_sparse(H)
[m,n]=size(H);
Ohmega=H*H';
for k=1:m
for i=1:m
for j=1:m
if j~=i
x(j)=abs(Ohmega(i,k)+Ohmega(j,k));
end
end
mask=x~=0; % mark the non-zero elements
x=x(mask); % keep the non-zero elements
x0=sort(x,'ascend'); % order the x so that lomed can be calculated
y(i)=x0(floor((length(x0)+1)/2)); % calculate the low median
end
y0=sort(y,'ascend'); % order the x so that lomed can be calculated
sm(k)=1.1926*y0(floor((length(y0)+1)/2));% calculate the low median
end
for k=1:m
for i=1:m
aux(i)=abs(Ohmega(k,i))/sm(i);
end
PS(k,1)=max(aux);
end
The above code was taken from https://in.mathworks.com/matlabcentral/fileexchange/60838-matlab-code-of-robust-gm-estimator-for-power-system-state-estimation-using-projection-statistics?focused=7509217&tab=function
1 Comment
"Can you help in optimizing the code below so that the execution time can be reduced? ... How to reduce it?"
Follow the guidelines in the MATLAB documentation:
Accepted Answer
More Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!