I found a 2013 post at MATLAB Answers,The author explains with detailed examples:the zero-matrix obtained by multiplying two empty arrays faster than constructing the zero-matrix directly.
The results of my test now are different from the author's test results in 2013, the following are my test results.From the current calculation results, it seems that it is faster to directly generate a zero matrix. My computer is:I7-6700 8G RAM Win10 matlab2020a. I don't understand why space-time matrix multiplication is faster in 2013. The Accepted anwser mentioned "doesn't allocate memory (R2012a, 64bit, Win7).", does this mean that what matlab got at that time was a fake zero matrix, so it was faster?
f=@() zeros(1000)
timeit(f)
f =
包含以下值的 function_handle:
@()zeros(1000)
ans =1.80924e-05
g=@() zeros(1000,0)*zeros(0,1000)
timeit(g)
g =
包含以下值的 function_handle:
@()zeros(1000,0)*zeros(0,1000)
ans =0.0021746854