MATLAB: How to find the amount of data generated/memory requirment for a program

least memory requirementleast run timeMATLABmemoryrun timetime vs memory

  • How to know the computational memory requirement of a program?
  • Also I would like to plot between computational time(run and time) and computational memory during a single run of a program.
  • How to obtain a least computational time and least computational memory requirement for a given computational capacity?
Thanks in advance!

Best Answer

Sorry. It is not possible to do these things in general.
MATLAB uses dynamically generated variables and arrays. So the memory required can easily vary according to the inputs of your function. And since temporary variables will be created by functions that are called, they may be arbitrarily large.
Suppose you have a function that calls a function. Down in the depths of one of these sub-functions, it sometimes chooses to call the function perms(1:1000), based perhaps on something unknowable. Or worse, suppose you have code that looks like this:
n = input('what is n?')
str = ['A = perms(1:',num2str(n),');'];
eval(str)
Yes, I know, obscene code. But if someone types in 1000 to that question, the result will be something that will take more space than any computer would have in this universe, even if every single elementary particle in the universe was a byte of RAM. Worse, MATLAB cannot know in advance this would happen. So it cannot look at that code without evaluating it to know ho much memory will be required.