I am using MATLAB. I have very large sparse matrices, and I want to perform a logical or bsxfun on each column of this matrix. There is a single for loop where in it is a single operation of logical to fill a sparse matrix. Here I include a sample function with some fake small data to see what I am trying to do;
function maskMat()
graph_temp = round(rand(10,10));
tic;
com_mat = round(rand(10,10));
com = round(rand(10,1));
for ii=1:length(graph_temp)    
    com_mat(:,ii) = logical(com ~= com(ii));
    %bsxfun works too but is slightly slower
    %com_mat(:,ii) =  bsxfun(@ne,com,com(ii));
end
toc;
com_mat = graph_temp .* com_mat;
graph_temp and com_mat are much bigger with around 1M rows and columns and the code is horribly slow do to the for loop. There is another relevant question here on SO, but I have not understood the theory behind it to see if I can apply those solutions to this problem as well. 
I was thinking to either write a mex c++ function or try to get some sort of nested arrayfun so that each logical/bsxfun operation is called as a subroutine of a greater function to avoid the for loop bottle neck. 
 
     
     
    