MATLAB POLYSPACE RELEASE NOTES Bedienungsanleitung Seite 170

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 240
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 169
4 Programming
Preallocation
If you cannot vec
torize a piece of code, you can make your
for loops g o faster
by preallocatin
g any vectors or arrays in which output results are stored. For
example, this co
de uses the function
zeros to preallocate the vector created in
the
for loop. Th
is makes the
for loop execute significantly faster:
r = zeros(32,1);
for n = 1:32
r(n) = rank(magic(n));
end
Without the prea
llocation in the previous example, the M ATLAB interpreter
enlarges the
r v
ector by one elem ent each time through the loop. Vector
preallocation
eliminates this step and res ults in faster execution.
4-32
Seitenansicht 169
1 2 ... 165 166 167 168 169 170 171 172 173 174 175 ... 239 240

Kommentare zu diesen Handbüchern

Keine Kommentare