用MATLAB生成一个100*100的矩阵,其中随机产生100个-1,其余数全部为零。

2024-12-14 18:01:39
推荐回答(2个)
回答1:

a = [-ones(100,1);zeros(9900,1)];
a = reshape(a(randperm(10000)),100,100);

回答2:

A=randint(100);
for I=1:100
for J=1:100
if A(I,J)==1
A(I,J)=-1;
end
end
end

A