Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

is there to make this double room to run faster?

1 Ansicht (letzte 30 Tage)
jenka
jenka am 20 Sep. 2012
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Walter Roberson
Walter Roberson am 20 Sep. 2012
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.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by