What is not "a finite, nonsparse, real integer vector" but looks like one? Error using circshift>ParseInputs (line 71)

9 views (last 30 days)
I'm using circshift to move a mask, but I'm running into a problem.
%pos_info is a 437x6 double matrix
%m is a 400x400x3 boolean matrix
pos_info(ind_values,4) = floor(x_shift);
pos_info(ind_values,3) = floor(y_shift);
%...%lot of other code%
shift_vals = int16([pos_info(ind_values,4) pos_info(ind_values,3)]);
m2 = circshift(m, shift_vals );
Gives me this error:
Error using circshift>ParseInputs (line 71)
Invalid shift type: must be a finite, nonsparse, real integer vector.
But:
K>> isvector(shift_vals)
ans =
1
K>> isinteger(shift_vals)
ans =
1
K>> issparse(shift_vals)
ans =
0
K>> isfinite(shift_vals)
ans =
1 1
Whatever the issue is must be subtle because:
K>> shift_vals
shift_vals =
220 174
K>> [220 174]
ans =
220 174
K>> m2 = circshift(m,[220 174]); %No error
If you look carefully, there is an extra space before the values for shift_vals on the display line. What am I missing?
Oh, and of course for completeness:
K>> shift_vals = [220 174]
shift_vals =
220 174
K>> m2 = circshift(m,shift_vals); % No error
Thanks in advance for any insights.

Answers (2)

Cedric
Cedric on 26 Mar 2013
Edited: Cedric on 26 Mar 2013
>> A = rand(4) > 0.5
A =
1 0 0 0
1 0 1 1
0 0 0 1
0 1 1 0
>> circshift(A, [2,3])
ans =
0 0 1 0
1 1 0 0
0 0 0 1
0 1 1 1
>> circshift(A, int16([2,3]))
Error using circshift>ParseInputs (line 71)
Invalid shift type: must be a finite, nonsparse, real integer vector.
So it's the type cast to int16 that is the problem.
  3 Comments
Cedric
Cedric on 26 Mar 2013
Edited: Cedric on 26 Mar 2013
There aren't that many options for failure here; if class(shift_vals) returns double, and numel(shift_vals) returns 2, then the only thing left, up to me, is that elements of shift_vals are not close enough to integers..
Try this
m2 = circshift(m, round(shift_vals)) ;
To illustrate based on my previous example,
>> circshift(A, [2+1*eps,3])
ans =
1 0 1 0
1 1 1 0
0 0 1 0
1 1 0 0
>> circshift(A, [2+2*eps,3])
Error using circshift>ParseInputs (line 71)
Invalid shift type: must be a finite, nonsparse, real integer vector.

Sign in to comment.


William
William on 22 Jul 2013
I had the same problem. I would call it a Matlab bug, or at least a blunder. I am using version 7.14.0.739 (R2012a)
Inside circshift, in parseInputs, the following test is made:
isInteger = all(isa(sh,'double') & (imag(sh)==0) & (sh==round(sh)));
where sh is an array of shift valus.
circshift needs this to be true, but it is only true for doubles with an integer value, not for integers e.g. int8, int16.
I just cast my shifts as doubles (they were int8 in my case) and it worked.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!