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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by