to be honest, though I solved the problem ,I didn't quite understand how to improve my code. I mean, the top of the solutions seemed quite strange to me .why by doing that the size would be smaller?
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.