This solution doesn't work on R2015a or R2015b. It seems that the behavior of circshift is changed. For example, circshift(sparse(logical([1 2 3])),[0 1]) on R2015b returns all zeros.
Hi Peng, it seems that last major changes to circshift were introduced in 2014a (dim selection added). I'm not able to check this version, 2015a also returns falses. Anyway, (not) nice bug :).
Hi Jan, I don't have 2014a either. But I was able to check with 2013a available here: http://anycodes.cn (On the left hand side, you can select to run MATLAB). While circshift(sparse(logical([1 2 3])),[0 1]) and circshift(sparse(+logical([1 2 3])),[0 1]) produce different output on 2015a and 2015b, they give the same result (up to a class difference) on 2013a.
It's definitely a bug. It seems the newest version of circshift doesn't handle sparse logical matrices properly. It somehow changes trues to falses, but treat them like nonzeros. This leads to some funny logical properties because of the way the algorithms for sparse matrices work. Check following code: A = circshift(sparse([false false true false true]),[0 1]); A, nonzeros(A); full(A), A|1, A&1, ~A, xor(A,1), xor(A,0), and(A,A), or(A,A), A==~~A, isequal(A,~~A), isequal(A|0,A), %(etc.);
B = sparse([false false true false true]); B, B = B([end 1:end-1]), ...
This is my favourite:
C = circshift(sparse(true),1);
Haha, this is definitely a funny example to elaborate on the improper behavior of circshift/sparse when dealing with sparse logical matrix. I agree with you this is a bug, but still not very sure the bug is due to circshift or sparse. Maybe somebody can report this bug to MATHWORKS...
Find the palindrome
Poker Series 11: selectBestHand
Replace multiples of 5 with NaN
Getting the absolute index from a matrix
Find best placement for ordered dominoes (harder)
Poker Series 04: isFlush
Find perfect placement of non-rotating dominoes (easier)
Getting the indices from a vector
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office