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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -