How do I pre-allocate memory for a complex matrix?
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to pre-allocate memory for a complex variable because the MATLAB documentation states that one should pre-allocate memory to speed up performance, i.e.
x = zeros(1000);
However, this only allocates the real-part. How do I pre-allocate a complex number? i.e.
x = zeros(1000) + j*zeros(1000);
This does not work. Instead it only allocates memory for the real part of the complex number array.
Akzeptierte Antwort
MathWorks Support Team
am 5 Jul. 2012
When MATLAB assigns a complex array, it scans the array to determine if the imaginary part is all zero. If this is the case, MATLAB removes the imaginary portion of the array to reserve memory.
Thus
x = zeros(1000) + j*zeros(1000);
is equivalent to:
x = zeros(1000);
To work around this issue, execute the following command:
x = complex(zeros(1000));
This will create a complex vector of the appropriate size.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!