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>
  1. There are 1000 elements (x=10 elements, y=10 elements, z=10 elements / cubic shape)
  2. I assigned that the 20% of elements are ‘2’ (Material number)
  3. I assigned that the 80% of elements are ‘1’ (Material number)
  4. Each position is the center of the elements
<array>
<Additional conditions>
  1. When the position of x = 4~7, y=4~7 and z=7 (holes), the material number is ‘3’.
  2. The 20% of elements except for the holes is ‘2’ (Material number)
  3. 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);

2 Comments

What is the question now?
I wonder how to make the code with additional condition 'number 1=
When the position of x = 4~7, y=4~7 and z=7 (holes), the material number is ‘3’.'

Sign in to comment.

Answers (0)

Categories

Find more on Computational Geometry in Help Center and File Exchange

Products

Release

R2020b

Asked:

on 22 Sep 2022

Edited:

on 23 Sep 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!