matlab - Get index of current element of a 2-D matrix within arrayfun -


let m matrix:

m = rand(1000, 2000); 

consider following code example:

a = zeros(size(m)); row = 1:1000     col = 1:2000         a(row, col) = m(row,col)*(row + col);     end end 

how compute matrix a without for loops?

there arrayfun function, don't know how index of current element:

a = arrayfun(@(x)(x*(index(1) + index(2))), m); %// how index??? 

perhaps there other solutions (and without loops)?

you can simple follows matrix represent row+col , multiply m

m = rand(1000, 2000); rowpluscol = bsxfun(@plus,(1:size(m,1)).',1:size(m,2)); = m.*rowpluscol; 

from experience bsxfun extremely powerful function , can save run time, , perfect example of that.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -