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 ]
Konstantine

Posts: 34
Registered: 5/3/11
Re: Successive Matrix Midpoint Operations
Posted: Mar 21, 2013 2:30 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kid7hl$e9l$1@newscl01ah.mathworks.com>...
> % 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


Bruno, this is excellent and so compact!

I'm going to try to see if I can work in my own operation into the code. Although the 'fun' tag is incredibly useful, the operation I want to perform is not a standard one.

Thank you so much for your time and brain cycles,
KP



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.