There will be very little memory difference. For a transient value, MATLAB creates everything about the storage except the symbol table entry with the name and a pointer to the descriptor.
My thinking was, that in the first solution Matlab actually creates two matrices (A and B), while in the second solution it handles both matrices parallel, only using memory for one matrix. Since I don't know Matlab's inner workings, I can't tell, though.
As far as I know, MATLAB only uses memory "in-place" when the same variable appears in a function call and in the assignment of the results from that call. There was another condition as well but I have forgotten it now.
I'm thinking it might have been Rick Rossom who listed the conditions in a comment, but it might have been someone else at MathWorks.
In any case the result depends on matrix dimensions and matrix initialization. If you want to improve memory management you should initialize a matrix/vector first and than try to improve matrix calculation.
Yeah, I know that writing it in C would be more efficient. The advantage of Matlab, however, is the simple fact, that I don't have to implement all the mathematical stuff.
My code is pretty fast, I believe. If there was any way to make it faster in Matlab, I'd do it. So I'm looking for ways. But if not, that's okay, too – creating, processing and plotting 100.000 data points on my several years old laptop within seconds or minutes sounds more than acceptable to me. ;)
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.