Is it possible to construct an array
A, without looping, where
A(i,j) = max(B(i),C(j)) and
C are column vectors?
bsxfun if your version has it.
A = bsxfun(@max, B, C.')
As per their documentation,
bsxfun expands the dimensions of the argument matrices on-the-fly, so does not use as much memory as
If the matrices are not too big,
repmat could work:
B = [2 3]; C = [0 1 2 3]; % Vectorize the vectors for a simplication B = B(:); C = C(:); A = max(repmat(B,1,length(C)),repmat(C',length(B),1));
For those interested, Comparing BSXFUN and REPMAT and Matlab - bsxfun no longer faster than repmat? address its relative efficiency with respect to
bsxfun used to be much faster, sometime ago. The difference seems shallower with the recent Matlab versions.