MATLAB POLYSPACE RELEASE NOTES Instrukcja Użytkownika Strona 170

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 240
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 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
Przeglądanie stron 169
1 2 ... 165 166 167 168 169 170 171 172 173 174 175 ... 239 240

Komentarze do niniejszej Instrukcji

Brak uwag