The Math Forum

Search All of the Math Forum:

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

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

Topic: element-wise operators, and bsxfun
Replies: 5   Last Post: May 17, 2014 9:06 AM

Advanced Search

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

Posts: 6
Registered: 1/29/14
element-wise operators, and bsxfun
Posted: May 15, 2014 8:20 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi all,

This is actually something I've been wondering for a while... Say I have a 1-by-4 vector A and a 5-by-4 matrix B. Now I want to assign the vector A to certain rows of B, but unfortunately you can't do something like


since the dimensions will mismatch. What I ended up doing is


which works but seems really ugly (and probably slow as well since I used repmat, which generates a large intermediary matrix).

So my first question: is there a better way to do this?

Another thought in a different context, though slightly related: it'll be great if the built-in element-wise multiplication (.*) and division (./ and .\) can be generalized to incorporate the function of bsxfun, so if use can do A.*B instead of repmat(A,5,1).*B or bsxfun(@times,A,B). I thought about it and it doesn't seem to introduce any ambiguity... we could also have .+ and .- instead of bsxfun(@plus) and bsxfun(@minus), and even some assignment operator like .= to solve my first problem!

My second question: is there a way to do something like this? Matlab doesn't seem to allow operator overload for built-in classes though...

Just wanted to share some of my random thoughts... But I'll appreciate it if someone bothers to answer my questions :)


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.