I would say that it is good practice to avoid creating temporary variables if they are too large. I guess I donβt need to explain in detail why this is bad. In most cases, there are alternatives that do not require temporary variables. If temporary variables are still needed, in many cases they are used only once. In this case, you can combine the expressions that you want to write into one expression (in case it does not become messy)
a = 1:10; b = a(a>5);
This will create this temporary variable anyway, but you don't have to clear it. Matlab does this cleanup on its own. However, if the pace becomes a problem, it is most likely due to design issues or too large functions. The only problem I noticed with high memory consumption is the memory problem. My experience is that the more information you store in memory, the faster the program runs. It takes a long time to recount some things. However, in most cases, there is a trade-off between memory efficiency and processing efficiency.
source share