arrays - Element wise multiplication of every row/column of a matrix with a vector -


i have matrix, named p_c_w having dimensions 6x7599 , other matrix named p_w having dimensions 1x7599. wish have element-wise multiplication unable that. size of rows of p_c_w , columns of p_w same, have taken transpose of p_c_w , stored in anss. error receving is: subscripted assignment dimension mismatch.

code below. can please help?

thanks lot in advance

anss=p_c_w' i=1:size(anss,1) j=1:size(p_w,2)     temp(j,i)=anss(i,j).*p_w(j);    end end 

use bsxfun:

a = [ 1 2 3 4 5;       1 2 3 4 5;       1 2 3 4 5 ];  b = [ 1 10 100 1000 10000];  c = bsxfun(@times,a,b)   

returns:

c =             1          20         300        4000       50000            1          20         300        4000       50000            1          20         300        4000       50000 

works same a' b'


so case:

temp = bsxfun(@times,p_c_w,p_w)  

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -