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)?
0 件のコメント
回答 (2 件)
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
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 Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!