给指定坐标以外的位置赋值,用matlab的矩阵条件索引就好了,这里写一个简短的示范代码,生成30000行1列的矩阵A,内容初始化为随机数,然后随机抽取1200个下标,使不在指定下标上的元素为0,结果放在B矩阵中,再plot一下以展示,以下仅7行代码:
A=rand(30000,1);
zhidingzuobiao=rand(1500,1)*30000+1;
zdzb=unique(floor(zhidingzuobiao));
zdzb=zdzb(1:1200);
nozdzb=unique([[1:30000]';zdzb]);
B=A;
B(nozdzb)=0;
plot(B);
追答
上面的是代码只是大概,不太详细,补充一个详细一点的。
clear all;
N=30000;
M=12000;
O=floor(M/5);
A=ones(N,1);
zdzb=unique(floor(rand(M+O,1)*N+1));
while(length(zdzb)
zdzb=[zdzb;unique(floor(rand(O,1)*N+1))];
zdzb=unique((zdzb));
end;
zdzb=zdzb(1:M);
fig=figure();
ax1=subplot(1,2,1);
plot(A);
ax2=subplot(1,2,2);
A(zdzb)=0;%*A(zdzb);
plot(A);
saveas(gca,'allexceptassign.jpg','jpg');