matlab - Create a horizontically stretched upper triangular matrix -
i'd create 4x12 matrix similar upper triangle matrix, looks this:
1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 so question is. efficient way create it? no loops, no cellfun. thanks.
one vectorized approach -
nrows = 4; ncols = 12; row_idx = repmat(1:nrows,ncols/nrows,1) out = bsxfun(@le,[1:nrows]',row_idx(:).')
Comments
Post a Comment