bsxfun - Matlab optimisation query, avoiding that repmat -
bsxfun - Matlab optimisation query, avoiding that repmat -
this simple question, can't see improve reply , maybe else can! here code:
example variables
nsim = 3000; nrow = 10000; info = zeros(1, 5, nrow); info (:, 1:4, :) = rand(4, nrow)*0.5; % 4 columns of duration values info (:, 5, :) = 1000; % 1 column of actual value basis.increaserate = 1 + (rand(nsim, 4)*0.1); example calculation
datawithsim = repmat(data(:, 1:4,:),nsim, 1, 1); increasefactors = bsxfun(@power, basis.increaserate, datawithsim); values = bsxfun(@times, data(:,5,:), prod(increasefactors,2)); the need repmat feels wrong, can't see way avoid it.
effectively i'm doing increase^data , didn't want have loop through 2 dimensions (sims or data rows). dummy info can ordered way choose, values output needs nsim nrow matrix.
any ideas welcome. thanks.
you don't need utilize repmat. can straight feed "submatrix" data -
increasefactors = bsxfun(@power, basis.increaserate, data(:,1:4,:)); bsxfun internally takes care of expansion of singleton dimensions, first dimension (rows) of data in case. since basis.increaserate has nsim rows , data(:,1,4,:) has 1 row, expanded have same number of rows, i.e. nsim , job of repmat-ing/expanding internally.
rest of code stays same.
matlab bsxfun
Comments
Post a Comment