Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Successive Matrix Midpoint Operations
Replies: 5   Last Post: Mar 21, 2013 5:58 PM

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 9,822 Registered: 7/26/08
Re: Successive Matrix Midpoint Operations
Posted: Mar 20, 2013 4:52 PM

% Save those in midfill.m

function a = midfill(a, fun)
a = md(a, 1, length(a), fun);
end

function a = md(a, istart, istop, fun)
if istop > istart+1
imid = floor(0.5*(istart+istop));
a(imid) = fun(a([istart istop]));
a = md(a, istart, imid, fun);
a = md(a, imid, istop, fun);
end
end

>> midfill([1 NaN NaN NaN NaN NaN NaN NaN 9],@mean)

ans =

1 2 3 4 5 6 7 8 9

>> midfill([1 NaN NaN NaN NaN NaN NaN NaN 9],@sum)

ans =

1 12 11 21 10 29 19 28 9

>> midfill([1 NaN NaN NaN NaN NaN NaN NaN 9],@prod)

ans =

1 9 9 81 9 729 81 729 9

% Bruno

Date Subject Author
3/20/13 Konstantine
3/20/13 Curious
3/20/13 Konstantine
3/20/13 Bruno Luong
3/21/13 Konstantine
3/21/13 Bruno Luong