Prev: Debug commands greyed out
Next: Sum of a cell
From: Doug Schwarz on 7 Apr 2010 16:04 Matt Fig wrote: > P = bsxfun(@times,M,V) Be careful: Since V was specified as a column vector the answer should be P = bsxfun(@times,M,V.'); Something like P = bsxfun(@times,M,V(:).'); is more general if the orientation of V is not known. -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.
From: Matt Fig on 7 Apr 2010 16:15 But Doug, by the example given: M = magic(2)*pi; V = [sqrt(2);sqrt(3)]; % Juliette's technique: P(:,1)=M(:,1).*V; P(:,2)=M(:,2).*V % BSXFUN P2 = bsxfun(@times,M,V) >>isequal(P,P2) ans = 1
From: Juliette Salexa on 7 Apr 2010 16:37 Matt is right, the transpose would multiply the rows rather than the columns. I did check the help: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/bsxfun.html and couldn't find any clues as to why it's called bsxfun Juliette
From: Matt Fig on 7 Apr 2010 16:40 Look at the help from the MATLAB command window. Notice the first line. >> help bsxfun BSXFUN Binary Singleton Expansion Function C = BSXFUN(FUNC,A,B) Apply an element-by-element binary operation to arrays A and B, with singleton expansion enabled. FUNC is a function handle. FUNC can either be a function handle for an M-function, or one of the following built-in functions: ........ etc., etc., ......
From: Steven Lord on 7 Apr 2010 16:50
"Juliette Salexa" <juliette.physicist(a)gmail.com> wrote in message news:hpiqdg$8el$1(a)fred.mathworks.com... > Matt is right, > the transpose would multiply the rows rather than the columns. > > > I did check the help: > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/bsxfun.html > > and couldn't find any clues as to why it's called bsxfun This is one case where the function help text has a bit more information than the function's documentation page. HELP BSXFUN says: > help bsxfun BSXFUN Binary Singleton Expansion Function *snip* I suppose you could say that the first line of the help should be: BSXFUN Binary Singleton eXpansion FUNction but I think it's close enough. Choosing names for new functions and new functionality can be (much) harder at times than people think, trust me. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ |