Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Niko
Posts:
6
Registered:
1/29/14


elementwise operators, and bsxfun
Posted:
May 15, 2014 8:20 PM


Hi all,
This is actually something I've been wondering for a while... Say I have a 1by4 vector A and a 5by4 matrix B. Now I want to assign the vector A to certain rows of B, but unfortunately you can't do something like
B([1,3,5],:)=A
since the dimensions will mismatch. What I ended up doing is
B([1,3,5],:)=repmat(A,3,1)
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 builtin elementwise 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 builtin classes though...
Just wanted to share some of my random thoughts... But I'll appreciate it if someone bothers to answer my questions :)
Niko



