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 계정에 로그인하거나 계정을 새로 만드십시오.