matlab怎么生成一个主对角为0,1随机的矩阵,其他元素为0

2024-11-28 04:54:03
推荐回答(2个)
回答1:

稍微修改一下一楼的:
a = round(rand(5,1));
b = diag(a);

回答2:

a = rand(10,1)>.5;
A = diag(a);