简体   繁体   English

我如何控制绘制的圆的数量

[英]how can i control the number of plotted circles

if i have matrix of three columns and 6 rows the columns represent the {x,y}coordinates of center of a circle and the third is the (z) which represent plot or not to plot the center the {z} is generated using rand operater to be either zero or one i want to not plot {x,y} whenever their {z} is zero but the number of ones must be always more than 3 how can i do that i have tried this 如果我有三列和六行的矩阵,则列代表圆心的{x,y}坐标,而第三列是(z)代表绘图或不绘图中心,{z}是使用rand生成的运算符为零或一个,我想在它们的{z}为零时不绘制{x,y},但总数必须始终大于3我该怎么做呢?

limit=6;
for i=1:raw
xy(i,1)=round(rand*(limit));
xy(i,2)=round(rand*(limit));
xy(i,3)=round(rand)*1;
if((xy(i,3)==1)>=3)
if(xy(i,3)==0);
xy(i,1)=inf;
xy(i,2)=inf;
end

end end 结束

Instead of the loop and random trigger generation: 代替循环和随机触发器的产生:

xy(ii,3)=round(rand);

you can use: 您可以使用:

xy=round(rand(limit,3));            %% Create limit x 3 random matrix
Ones=[ones(3,1);zeros(limit-3,1)];  %% Create column vector of [1;1;1;0;...;0]
Indices=randperm(limit);            %% Create random permutation of indices
xy(:,3)=Ones(Indices);              %% Shuffle Ones vector by randomly and assign it to 3rd column assigned Indices
xy(find(xy(:,3)==0),1:2)=inf;       %% Assign NaN value to rows where xy(ii,3)==0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM