Skip to Main Content
Programming in MATLAB ®: A Problem-Solving Approach by Pearson
book

Programming in MATLAB ®: A Problem-Solving Approach by Pearson

by Ram N. Patel, Ankush Mittal
May 2024
Intermediate to advanced content levelIntermediate to advanced
433 pages
13h 7m
English
Pearson India
Content preview from Programming in MATLAB ®: A Problem-Solving Approach by Pearson
Coding Tips for Memory Usage É 211
7.4.1 Preallocation of Arrays
Preallocation is an important technique that can help speed up your code. Each variable in
MATLAB must be stored in one contiguous block of memory addresses. If memory for a large
variable is not allocated at the beginning of the program, then the memory around it may be
allocated, restricting its space to expand, resulting in out of memory errors.
Example 7.2(a)
Consider the following piece of typical code that constructs a vector with 10000 elements:
%% Version 1 code
clear;
t = cputime;
x(1) = 0.31;
for i = 2:10000
x(i) = ( 1 - 1.3*x(i-1))^2;
end
elapsed1 = cputime-t
The preceding statements ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Applied Numerical Methods Using MATLAB, 2nd Edition

Applied Numerical Methods Using MATLAB, 2nd Edition

Won Y. Yang, Wenwu Cao, Jaekwon Kim, Kyung W. Park, Ho-Hyun Park, Jingon Joung, Jong-Suk Ro, Han L. Lee, Cheol-Ho Hong, Taeho Im
MATLAB Recipes: A Problem-Solution Approach

MATLAB Recipes: A Problem-Solution Approach

Michael Paluszek, Stephanie Thomas
Practical MATLAB Deep Learning: A Projects-Based Approach

Practical MATLAB Deep Learning: A Projects-Based Approach

Michael Paluszek, Stephanie Thomas, Eric Ham

Publisher Resources

ISBN: 9781306983440Publisher Website