Complex variable
显示 更早的评论
Hello, In a simulation I define a complex array to compute some physical quantity as follows : j_e_real = zeros(length(h),length(t)); j_e = complex(j_e_real,0);
Nevertheless, at the beginning of my simulation (while loop), real numbers are written into the array j_e. This works well until complex numbers need to be written further in the same array j_e (later in my while loop).
This totally froze Matlab. By using 'whos', I checked that my array j_e is still defined as a complex array.
When I artificially add an epsilon complex quantity each time I write something in that array, it doesn't froze.
Any ideas, suggestion? It seems that the memory is not allocated in a proper way, but I don't understand why.
Thx, Maxime
3 个评论
Jan
2011-7-11
Please explain "this totally froze Matlab" with any details. Do you get an error message or does Matlab crash? Please show us the lines, which causes the problems, otherwise any answer must be a pure speculation.
Kooglof
2011-7-11
Jan
2011-7-11
@Kooglof: without seeing your code, the assistence is a pure guessing and therefore inefficient.
Do you need j_e_real at all? If not, it wastes memory and this would be sufficient: j_e = zeros(length(h),length(t)). Then the memory for the complex values is allocated automatically the first time a complex value is assigned to j_e.
I suggest to use the PROFILEr to find out, which lines are slower than with real values.
回答(1 个)
Titus Edelhofer
2011-7-11
0 个投票
Hi,
I guess the following is happening: the real part and the imag part are stored in two different arrays. Depending on the operating system and the version of MATLAB you are using, MATLAB does not allocate memory for the imaginary part as long as all imag parts are zero. The moment the first imaginary part is non zero, the memory is allocated. Therefore, next guess, the moment the first non zero imaginary part is written into the array, you should see in the task manager (or using top in linux) a large jump in memory usage (making the operating system swap memory, which is slow).
Titus
1 个评论
Jan
2011-7-11
a = rand(1000, 1000); b = complex(a, 0);
Now "b(end,end)=i" does not get more memory from the OS, according to the Windows taskmanager.
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!