如何使用 Octave 将一列 1 和 0 插入到矩阵中?

How to insert a column of ones and zeros into a matrix using Octave?

假设我有一个包含一组整数的矩阵。我想使用检查 rand > 0.5 将 1 和 0 的随机向量添加到我的矩阵中。我该怎么做?

只有一个 6x1 矩阵,但您应该明白了。

octave:1> a = [7;8;2;3;6;7];
octave:2> a = [a, rand(size(a))>0.5]
a =

   7   0
   8   1
   2   1
   3   0
   6   1
   7   0