I’d like to multiply a random number vector PT(n)=rand(1,n) by a matrix M(mxn) but want to have a different random vector for each column multiplication. Is it possible in Matlab?
E.g. PT=rand(1,4);
`PT*(1 0 0 0;...
0 0 0 1;...
0 1 0 0;...
0 0 0 1);
but where PT changes for each column multiplication. The only way I can think of is make PT=rand(4,4)and then take diag(PT*M) but it’s very expensive if my matrix M is large.
Any thoughts?
Cheers
Suplemental
using @Nasser arrayfun code takes 3 times longer than a for loop. I see it’s normal but why the big difference?
I am not sure if I understood exactly what you are asking.
But if you mean you have a matrix of vectors, and you want to multiply another matrix by each one of these vectors then one way is to use
arrayfun.For example: Here we multiply a 5 by 4 matrix with 3 vectors, each is 4 by 1.
The result is 3 vectors, each is 5 by 1
gives