Re: circular shifting a vector/matrix - Problem



Jos wrote:
jkvdpoel wrote:

< SNIP circshift to slow ...

Here you have a piece of my code:

corrCoef = zeros(1, numColMatrix01);
for shiftSize = 1:numColMatrix01,
corrCoef(shiftSize) = corr2(Matrix01, Matrix02);
Matrix01 = circshift(Matrix01, [0 shiftSize]);

Are you sure you want to shift like this (iteration 1, 1 shift,
iteration 2, 2 shifts of the already shifted (!!) matrix)? Probably
not ...

Using indexing may be much faster.

for i=1:size(M1,2),
C = corr2(M1,M2) ;
M1 = M1(:,[2:end 1]) ; % shift columns
end

or more directly
nc2 = size(M1,2) ;
for i = 1:nc2,
C(i) = corr2(M1(:,[i:nc2 1:(i-1)]),M2) ;
end

hth
Jos

Hi, Jos (and all the others who kindly anwered to my question):

Quoting you,

Are you sure you want to shift like this (iteration 1, 1 shift,
iteration 2, 2 shifts of the already shifted (!!) matrix)? Probably
not ...

Suddenly, and _many_ thanks to your message, I realised that this was
_not_ what I really wanted. I wanted something like this: (iteration 1,
1 shift, iteration _2_, _1_ shift of the already shifted matrix,
iteration _3_, _1_ shift of the already shifted matrix, ...). But the
question remains (because it is still burning my brain)...

Does your solution is related to my question or is related to your
point of view (the one that "was _not_ what I wanted")? Could you
clarify this for me, please?

Many thanks in advance for you and all the other who answered so fast
to my question,

JanKees Poel

.



Relevant Pages

  • Re: bit operations and parity
    ... Only one shift is needed per iteration, so there are no questions about whether the processor has a barrel shifter. ... exercise for the reader. ... (Extending it to float and double is left ...
    (comp.lang.java.programmer)
  • security considerations for: set x dir/[*] dir/*
    ... The following steps for the iteration are: ... contents of $is under the control of an attacker (and this shell ...
    (comp.unix.shell)
  • Re: bit operations and parity
    ... Mayeul wrote in ... The table could be computed offline and stored in the source code, ... for the shift at the end of each iteration. ...
    (comp.lang.java.programmer)
  • Re: Position of title changes in each loop. Why?
    ... So I expect titleposition to be the ... You are shifting the title slightly up in each iteration. ... I assume you are plotting on the same axis in each loop. ... You only need to shift it once. ...
    (comp.soft-sys.matlab)
  • Re: convergence of QR-algorithm
    ... >Bill, yes I'm doing all of that., alongside using a shift that is the ... In either case the bottom two elements below the diagonal should ... >the one I'm using as it involves more calculation at each iteration. ... >case convergence could never occur. ...
    (sci.math.num-analysis)