フィルターのクリア

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 件のコメント
Seetha Rama Raju Sanapala
Seetha Rama Raju Sanapala 2015 年 10 月 6 日
We are talking about matrices. I think if they are matrices, and not vectors, there is no difference.
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 Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by