Info

此问题已关闭。 请重新打开它进行编辑或回答。

is there to make this double room to run faster?

1 次查看(过去 30 天)
Hi guys, I am trying to reduce the cost of running my program: is there a way to reduce two pieces of code: FIRST ONE:
for i=1:sz(2)
for j=1:sz(3)
rms_NTG10(ls,i,j) = sqrt(mean(err_NTG10(:,i,j).^2));
rms_NTG20(ls,i,j) = sqrt(mean(err_NTG20(:,i,j).^2));
rms_NTG30(ls,i,j) = sqrt(mean(err_NTG30(:,i,j).^2));
rms_NTG40(ls,i,j) = sqrt(mean(err_NTG40(:,i,j).^2));
rms_NTG50(ls,i,j) = sqrt(mean(err_NTG50(:,i,j).^2));
rms_NTG60(ls,i,j) = sqrt(mean(err_NTG60(:,i,j).^2));
rms_NTG70(ls,i,j) = sqrt(mean(err_NTG70(:,i,j).^2));
rms_NTG80(ls,i,j) = sqrt(mean(err_NTG80(:,i,j).^2));
rms_NTG90(ls,i,j) = sqrt(mean(err_NTG90(:,i,j).^2));
rms_NTG100(ls,i,j) = sqrt(mean(err_NTG100(:,i,j).^2));
end
end
SECOND ONE:
for i=1:sz(2)
for j=1:sz(3)
accum_ar(i,j,accum_index(i,j)) = accum_ar(i,j,accum_index(i,j)) + 1;
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2012-9-20
In the first situation, you can run the sqrt() after the rest of the calculations, such as
rms_NTG10(ls,:,:) = sqrt(rms_NTG10(ls,:,:));
Also, you can square the errors before you start:
err_sq_NTG10 = err_NTG10.^2;
and then pull out the part of that you need for each mean ()
Reducing the number of calls to identical operations is usually faster.

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by