how to use circshift in matlab

I have a array of indeces, so they must be positive, but some of them are negative, for instance for a array of m elements, I want to say if i=-1 put i=M-1, and if i=-2 put it M-2, how can I use circshift?

댓글 수: 3

Image Analyst
Image Analyst 2012년 12월 21일
편집: Image Analyst 2012년 12월 21일
Please give an example. Just saying "put it M-2" is not descriptive enough. circshift works on the whole array, it does not use different shifts on an element by element basis.
ss
ss 2012년 12월 21일
I mean my data are periodic, yes you are right, my problem is exactly what you say. I find indeces that their number is M-an M-dimensional array-but I want to say if one of this numbers is out of 0 to M-1, select it such as it be between 0 to M-1, for instance if it is -1 select it as M-1, I don't want to use if loop, is there any method?
Image Analyst
Image Analyst 2012년 12월 21일
I think Matt is right - you want mod(), not circshift().

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2012년 12월 21일
편집: Matt J 2012년 12월 21일

1 개 추천

What you're trying to do does not seem to require CIRCSHIFT at all, but merely
mod(i,M)

댓글 수: 1

If positive integers are desired which must always fall in the range 1<=k<=M, then a modification of the 'mod' function would seem to be called for. To "add" p to k, do this:
k_plus_p = mod(k+p-1,M)+1
This gives the alteration to an index k of an element of an array which occurs with a circular shift of amount p.
Roger Stafford

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

ss
2012년 12월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by