Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
Considering only 2-D arrays i.e. matrices only, is there a difference between flip(a) and flipud(a)?

Risposte (2)

Star Strider
Star Strider il 6 Ott 2015
As I read the documentation: No.

Walter Roberson
Walter Roberson il 6 Ott 2015
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 Commenti
Walter Roberson
Walter Roberson il 7 Ott 2015
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.

Accedi per commentare.

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by