Considering only 2-D arrays i.e. matrices only, is there a difference between flip(a) and fliplud(a)?

1 次查看(过去 30 天)
Considering only 2-D arrays i.e. matrices only, is there a difference between flip(a) and flipud(a)?

回答(2 个)

Star Strider
Star Strider 2015-10-6
As I read the documentation: No.

Walter Roberson
Walter Roberson 2015-10-6
flipud always operates on the first dimension even if it is singular. flip operates on the first non-singular dimension by default.
For example flip(1:5) is [5 4 3 2 1] because the first non-singular dimension is the second dimension, but flipud(1:5) would be [1 2 3 4 5] because the flip is done on the first dimension.
  2 个评论
Walter Roberson
Walter Roberson 2015-10-7
In MATLAB, vectors are matrices which happen to be singular (length 1) on all except 1 dimension.
If you are certain that your array has a non-singular first dimension, then flip(X) and flip(X,1) and flipud(X) would be equivalent. However, either flip(X,1) or flipud(X) would be preferred coding as it would indicate to the people reading the code that you specifically considered the possibility that your input might be singular on the first dimension and you definitely want the first dimension. It saves the reader from having to trace the code backwards to prove that it is impossible for the input to have a singular first dimension, which might not be possible as it might rely upon the assumption that an input file has multiple rows.
It is best practice to code the dimension of the operation unless you want it to be flexible about which dimension to use, unless perhaps it is completely obvious from the immediate context which dimension will be used.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by