Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,813
Registered: 7/26/08
Re: Successive Matrix Midpoint Operations
Posted: Mar 20, 2013 4:52 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

% 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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.