Optimizing a 'for' loop
显示 更早的评论
%%Average roughness
for i=1:numel(M)
k= abs((mean(M)-M(i)))/numel(M);
avg=avg+k;
end
With the use of above code, i'm calculating average roughness of a surface. The surface height values are stored in the matrix M. The problem is, it takes half an hour to compute as the matrix is 1024*1280. Any better method to do it? As i have atleast 500 sets of data to compute.
采纳的回答
更多回答(1 个)
Matt Kindig
2012-4-11
0 个投票
You algorithm isn't quite clear. What is the dimension of mean(M)? Why do you subtract M(i) from it each time? Can you clarify the formula for average roughness that you are trying to implement?
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!