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 :)