Fliplr and flipud functions no longer accepts vectors

5 次查看(过去 30 天)
Fliplr and flipud functions does not accept vectors in R2010bsp1. Don't know when (or why) this change was introduced, but finding out exactly why my old code won't work anymore is pretty straightforward:
My old matlab (r2007b) uses if(ndims(x)~=2) to determine if the inputs to flipud/fliplr is valid, which works fine for vectors (1-by-n or n-by-1 arrays). R2010b uses ~ismatrix(x), which requires that x must be of size n-by-m (where m,n>1). And yes, these are elementary matlab functions located in toolbox\matlab\elmat\ ... no obvious reason to change those, I would think.
The documentation is NOT updated - I quote from doc fliplr: If A is a row vector, then fliplr(A) returns a vector of the same length with the order of its elements reversed. If A is a column vector, then fliplr(A) simply returns A. Clearly, this is no longer correct.
My question: Why on earth was this change made????
It has made A LOT of my code incompatible with r2010b. I can't be the only one who has experienced this?
  2 个评论
Walter Roberson
Walter Roberson 2011-3-22
By the way, this exact same issue came up for someone in the discussion area, sometime around mid December; the solution was exactly the same, that they had a conflicting routine in their path.
MarionJ
MarionJ 2018-7-31
I have exactly the same Problem. I have a 92 x 3 double Matrix and fliplr has no effect. ISMATRIX returns however the value '1'. What did you change to make it work?

请先登录,再进行评论。

采纳的回答

Matt Fig
Matt Fig 2011-3-22
According to the documentation, ISMATRIX returns true if size(A) is [m,n] for non-negative m,n. Thus a vector should return true. I suspect the problem lies elsewhere.
Is the ISMATRIX an M-file or a built-in? If it is an M-file, could you check the code to verify the doc is correct?
I noticed there is an ISMATRIX on the FEX, are you sure you aren't using a custom version? Will you also check that you are not using a custom FLIPLR?

更多回答(3 个)

Matt Tearle
Matt Tearle 2011-3-22
ismatrix is true for a vector or even a scalar -- everything in MATLAB is a matrix unless you force it not to be (eg a 3-D array). Have you actually tested flipud on vectors? This works fine for me in both R2010b and R2011a:
x = 1:5
fliplr(x)
flipud(x)
flipud(x')
fliplr(x')
>> which ismatrix
built-in (C:\Program Files\MATLAB\R2010b\toolbox\matlab\elmat\ismatrix)
>> which flipud
C:\Program Files\MATLAB\R2010b\toolbox\matlab\elmat\flipud.m
>> which fliplr
C:\Program Files\MATLAB\R2010b\toolbox\matlab\elmat\fliplr.m

Jan Jensen
Jan Jensen 2011-3-22
Thanks Matt and Matt - and yes, the deviation from normal everything is a matrice - behavior certainly is puzzling, isn't it?
The problem was in another library that had its own version of ismatrix which didn't accept vectors as valid matrices.
Thanks for putting me on the right track - I wouldn't have checked that without your input.

John D'Errico
John D'Errico 2011-3-22
This is surely the expected behavior of these tools.
>> flipud(1:5)
ans =
1 2 3 4 5
applied to a row vector, flipud should be a no-op, returning the input vector unchanged. Of course, fliplr does reverse the order.
>> fliplr(1:5)
ans =
5 4 3 2 1
The above test was performed in both R2010b and in the prerelease R2011 version, with no problems found. So I'm not sure what the issue is here, unless you are indeed using a non-standard form of ismatrix.
  2 个评论
Jan Jensen
Jan Jensen 2011-3-22
Correct, the problem was in deed caused by a non-standard form of ismatrix.
Name-space conflicts in user added libraries is fun... ;)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by