Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 31 characters in body
Source Link
Robert Seifert
  • 25.3k
  • 13
  • 75
  • 117

use bsxfunbsxfun:

A = [ 1 2 3 ;4 5; 1 2 3 ;4 5; 1 2 3 ;  4 5 ];  1 2 3 ]; B = [ 1  ; 10 ;  100 ;  1000 ];10000]; C = bsxfun(@times,A,B)  

returns:

C = 1 20 2 300 3 4000 50000 10 1 20 300 30  4000 100 50000  200 1 300  100020 2000 300 3000 4000 50000 

Works the same for A' with B'


so for your case:

temp = bsxfun(@times,p_c_w,p_w) 

use bsxfun:

A = [ 1 2 3 ; 1 2 3 ; 1 2 3 ;  1 2 3 ]; B = [ 1  ; 10 ;  100 ;  1000 ]; C = bsxfun(@times,A,B) 

returns:

C = 1 2 3 10 20 30  100 200 300  1000 2000 3000 

so for your case:

temp = bsxfun(@times,p_c_w,p_w) 

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 the same for A' with B'


so for your case:

temp = bsxfun(@times,p_c_w,p_w) 
Source Link
Robert Seifert
  • 25.3k
  • 13
  • 75
  • 117

use bsxfun:

A = [ 1 2 3 ; 1 2 3 ; 1 2 3 ; 1 2 3 ]; B = [ 1 ; 10 ; 100 ; 1000 ]; C = bsxfun(@times,A,B) 

returns:

C = 1 2 3 10 20 30 100 200 300 1000 2000 3000 

so for your case:

temp = bsxfun(@times,p_c_w,p_w)