From: Matt on 19 Apr 2010 10:14 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hqb886$jba$1(a)fred.mathworks.com>... > "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hqb14t$t62$1(a)fred.mathworks.com>... > > ... If the intent is to substitute for each element (except those on the left and right boundaries) the average of its previous value along with those of the previous values of the elements to the immediate left and right, then it would *not* be correct. As you and ImageAnalyst are already aware, as x advances it is using as its x-1 value, not the original value but the value as altered just before that, which is an unusual procedure. In the end that makes each subsequent value some sort of weighted average of all elements to the left along with the one to the right. For example the new m_new(3,:) would equal > > > > 1/9*m_old(1,:)+1/9*m_old(2,:)+4/9*m_old(3,:)+3/9*m_old(4,:) > > > > where these latter m_old values refer to previous values. I seriously doubt that this is the intent of the coding, and Matt may not yet be aware of this. To do what I suspect was the actual intent would require making the replacements in a separate matrix as they occur and then substituting all the new values back into the old matrix after the for-loops are finished, (though of course this can more easily be done in a vectorized manner.) > > > > The only explanation I have for not seeing an alteration in your matrix, Matt, would be that each row already varies linearly along its length. Then it would remain unchanged by the code. For example 3,3.25,3.5,3.75,4,4.25, etc., along a row would remain unaffected (except for small round off errors.) > > > > Roger Stafford > -------- > My apologies. My directions are turned around in the above. Where I said 'left' and 'right' should read 'up' and 'down', respectively, and where I said 'row' should read 'column'. > > Roger Stafford Ok, thanks, I've been able to fix the problem. You where indeed all correct that the result that I would be getting with the code I wrote was not as intended, thanks for bringing that to my attention! ~Matt |