1
votes

I have an array of N position vectors which form an N-by-3 matrix. I want to transform these position vectors to another coordinate system. The 3-by-3 rotational transformation matrix is same for all position vectors. How can I use arrayfun or bsxfun for this purpose for minimising computation time?

1
what transformation do you want? There are various availabeRobert Seifert
FYI arrayfun is very unlikely to minimise computation time over a simple for-loop. It's just wrapping a loop up with a bit of extra overhead. bsxfun does produce a speedup often, however matrix multiplication with bsxfun is not simple. Luckily for you, you need neither as * will suffice.Dan
@Dan, I wonder though: why is N-by-3 better than Nx3? Both N and 3 should be code, I believe (but the former definitely). And you don't need superfluous edits for a title change.Andras Deak
@AndrasDeak so mostly because N and N are completely different in this case and the ambiguity caused by writing Nx3 is precisely why I prefer to use MATLAB's documentation's formatting. Nx3 could be a variable name, N*3 is even worse as it could be the matix N (which actually exists in this case!) multiplied by the scalar 3. Since N and 3 in this case are never actually typed in code but rather almost meta data to the data structures in the code, I prefer to not use code tags for them. If it was n-by-3 I would though if n was a variable.Dan
@AndrasDeak I see he said array of N position vectors which I misread as an array N of position vectors. Mostly because I expect something in code tags to be a variable, but in this instance I see my error and the two Ns are indeed the same. Personally I think that neither should be in code tags though.Dan

1 Answers

4
votes

You can just apply it in one shot using matrix multiplication:

NTransformed = N*transformationMatrix