for loop/periodic implementation for number or arrays?
2 views (last 30 days)
Hatim Altarteer on 31 Aug 2021
i have 8 arrays of 100x3 configuration. i want to make a for loop (or another method is also appreciated) to accont for 2 constraints.
if the value of a number in the array is less than 1, replace it with one. also, if a number in the array is greater than nx + 1, put it back to 1. (nx is the upper limit, say nx = 100)
array1 = [x0,y0,z0];
array2 = [x0,y0,z1];
array3 = [x0,y1,z0];
array4 = [x0,y1,z1];
array5 = [x1,y0,z0];
array6 = [x1,y0,z1];
array7 = [x1,y1,z0];
array8 = [x1,y1,z1];
where xyz0 and xyz1 are coordinates of a particel in the xyz plane. the attached file is an example of x0 where it includes the location of the "x" coordinates of 100 particels. the same applies for the rest of yz0 and xyz1.
thanks in advance!
Fabio Freschi on 31 Aug 2021
If you want to force the max and min values of your vectors, you can preprocess them
x0(x0 < 1 & x0 > nx+1) = 1;
If the boundary value is different youy can split the instruction in two
x0(x0 < 1) = 1;
x0(x0 > nx+1) = nx+1; % for example
repeat for y0 z0 x1 y1 z1 and then create your 8 arrays