Flip Arrays
Note
The file submission referenced in this post is no longer available on File Exchange.
I love small, simple, useful functions. Many of my own submissions are not much more than one line of code (wopen, goto) that I use dozens of times a week. Duane Hanselman submitted a great one the other day. FLIPARRAY works just like FLIPUD and FLIPLR, except that it doesn’t require you to figure out if the input is a row or column vector first. It also extends nicely to support multidimensional arrays, preserving the array shape.
Duane received some grief over such a “simple” submission, including a nomination for removal. I couldn’t disagree more – I think submissions like this make the File Exchange great, and make MATLAB much more enjoyable to live with. The fact that it’s only one line of code tells me two things:
- MATLAB has a very compact, efficient language.
- Duane knows how to use it to his advantage.
I don’t know about you, but I’d much rather type:
>> x = fliparray(x)
than
>> x(:)=x(end:-1:1);
It takes less thought, is easier to type, and makes my code infinitely more readable. Thanks, Duane.
评论
要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。