因为条件中的矩阵不是唯一的,所以用随机矩阵的形式给出。
m= ; n= ; %m,n自己赋值
A=zeros(m,n);
a=ceil(rand(1,n)*n);
for i=1:n
A(a(i),i)=0;
end
可以先生成全零矩阵,再每一行随机把1个零变为1呗
Here are some examples:
>> random01(4,7)
ans =
0 0 0 1 0 0 0
1 0 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 0 1 0 0
>> random01(4,7)
ans =
0 0 0 0 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 1
0 0 0 1 0 0 0
>> random01(4,7)
ans =
0 0 0 0 1 0 0
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 0 1 0 0 0
Where function random01() is defined as:
function [ M ] = random01( m, n )
t0 = zeros(m, n);
t0(1:m, 1:m) = eye(m);
t1 = t0(randperm(m),:);
M = t1 ( :, randperm(n));
end