circshift error in loop

10 views (last 30 days)
Qiuyang
Qiuyang on 15 Oct 2012
hi, my code is
for k = 1:last_frame-1
ca=circshift(im,[k,0]);
da = im - ca;
clear ca
da = da(da(:,4)==0 & da(:,3)==k,:);
da = da(1:k:end,:);
msdx(k) = sum(da(:,1).*da(:,1));
msdy(k) = sum(da(:,2).*da(:,2));
nmsd(k) = length(da(:,1));
end
here im is 2D array, last_frame is a integer number
??? Error using ==> circshift at 37 Invalid shift type: must be a finite, nonsparse, real integer vector.
what's wrong with this code?
  1 Comment
Matt Fig
Matt Fig on 15 Oct 2012
Are you sure that is where the error is occuring? I can see nothing wrong with your use of CIRCSHIFT.

Sign in to comment.

Answers (1)

Matt J
Matt J on 16 Oct 2012
Edited: Matt J on 16 Oct 2012
Just a guess. last_frame was accidentally given a value like NaN or something like that. Hence, k also has a bad value when it is passed to CIRCSHIFT.
The way to find out is to use DBSTOP, or breakpoints.
  2 Comments
Qiuyang
Qiuyang on 16 Oct 2012
I both printed out last_frame and k, they are 500 and 1 respectively. What else could be the reason?
Matt J
Matt J on 16 Oct 2012
Well, use DBSTOP anyway. When it stops inside circshift again, check the value of the variable p. Then use DBUP to see what value is being passed to circshift as p.

Sign in to comment.

Categories

Find more on Signal Generation and Preprocessing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!