I’ve found that the huge strength of MATLAB is that it frees me to rapidly prototype numerical math problems – before I design a targeted solution. Such esoteric efficiencies as above are very clever and much credit goes to the person who presented it, however, this distracts rather than adds significant value to my use of MATLAB. Depending on the target machine (Desktop workstation or embedded device) I will ultimately use C/C++, assembly and VHDL to implement my process efficient code – never an interpreted language.
This is an update since I had one person ask about my post...
I believe that speed is only one metric of performance, another is memory utilization. The key in this problem is the “type” of the variable stored internally. By using ans=1:10; the variable ans is (I believe) of the type double precision floating point (8 Bytes for each number). On the other hand by using str2num, a cast to an array of Characters (1 Byte each) is used to tightly store the tiny integer range of numbers needed. Thus the memory required to store ans is 8 times less.
SO, I’m not sure how they actually score (or weight) the importance between memory efficiency and execution time (and across multiple platforms and OS’s) since in your case you claim a faster execution time without the casting. This would need to be asked to a Mathworks person with specific insight to their code – sorry.
And back to my soapbox point… I’m using a machine that has 12 GB of RAM, so the difference between using 10 bytes or 80 bytes is not important to me.
HOWEVER, understanding this issue IS important so my hat is off to the Cody folks for the great (and fun) challenge!
Hope that helps!
The metric used to evaluate the performance of a solution is http://www.mathworks.com/matlabcentral/fileexchange/34754-calculate-size
As you can see if you inspect the code, it has nothing to do with speed or memory. That is why I proposed this solution, in order to show that you can become the leader with a code that is not efficient at all, either in execution speed or in memory use. Although I think the idea of Cody is great and challenging I believe that the metric that is used nowadays should be rethought.
Cannot be reproduced, creates an error in execution in R2016a.
Distance walked 1D
Add two numbers
Length of a short side
Extra safe primes
Remove the polynomials that have positive real elements of their roots.
Prime factor digits
Make a checkerboard matrix
Get the area codes from a list of phone numbers
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office