From: Ray on 24 Jun 2010 19:08 I have a cell array (1xN) that contains a matrix in each cell. The matrices could all be of different length. I want to perform an operation on the matrices such as multiply each of them by a different number. How can I do this efficiently? Example: a = {[1 2 3]; [5 7 8 3]; [2 4]} b = [10; 5; 2] I want to produce a cell array that is would essentially be {b(1)*a{1}; b(2)*a{2};b(3)*a{3}} . How do I do this without resorting to for loops? I'm hoping to avoid for loops because N could be quite long (>200).
From: Matt Fig on 24 Jun 2010 19:14 cellfun(@times,a,num2cell(b),'Un',0)
From: Ray Durrants on 29 Jun 2010 02:56 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <i00ors$kae$1(a)fred.mathworks.com>... > cellfun(@times,a,num2cell(b),'Un',0) Thanks for that, Matt. It was including the 'Un',0 that had me stumped.
|
Pages: 1 Prev: Simulink model, GUI, executables and online apps? Next: MCR bug? |