Creatng Array code using randperm function
显示 更早的评论
Creatng Array code using randperm function
I’ve created the Array code using randperm function.
I would like to improve some part.
My question is how to add the additional conditions?
<Previous conditions>
- There are 1000 elements (x=10 elements, y=10 elements, z=10 elements / cubic shape)
- I assigned that the 20% of elements are ‘2’ (Material number)
- I assigned that the 80% of elements are ‘1’ (Material number)
- Each position is the center of the elements

<array>
<Additional conditions>
- When the position of x = 4~7, y=4~7 and z=7 (holes), the material number is ‘3’.
- The 20% of elements except for the holes is ‘2’ (Material number)
- The 80% of elements except for the holes is ‘1’ (Material number)

<previous code>
clc; clear; close all
n = 1000; p = randperm(n); array = zeros(n,1);
Vf = 0.2;
Num = Vf*n;
%% Input
Xlength = 0.5;
Ylength = 0.5;
Zlength = 0.5;
XNum = 10;
YNum = 10;
ZNum = 10;
Xmin = -0*Xlength/2;
Ymin = -1*Ylength/2;
Zmin = -1*Zlength/2;
X = -0.25; Y = -0.25; Z = -0.25;
for i=1:XNum
Xnew = X+Xlength;
X = Xnew;
Xoriginal(i) = X;
end
for i=1:YNum
Ynew = Y+Ylength;
Y = Ynew;
Yoriginal(i) = Y;
end
for i=1:ZNum
Znew = Z+Zlength;
Z = Znew;
Zoriginal(i) = Z;
end
for i = 1:Num
array(p(i)) = 10e9;
end
[X,Y,Z] = meshgrid(Xoriginal,Yoriginal,Zoriginal);
X = X(:);
Y = Y(:);
Z = Z(:);
POS = [X Y Z array];
SzPOS = size(POS);
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Computational Geometry 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!