I want to create a certain number n
of 2d random data
, which have the following structure:
data[[1]]
{1,{{1.02132,1.01263},{1.03484,1.9117},{1.03486,2.98586},
{2.02018,1.08195},{1.99074,2.08351},{2.08115,2.93116},
{2.91449,0.937876},{2.90946,2.04354},{2.91203,3.00754}
}
}
Here is my code for a squared lattice:
SeedRandom["1"];
ni = 5;
r = 0.1;
np = 9;
snp = Round@Sqrt[np];
data = Table[{n, Flatten[Table[{i, j} + RandomReal[{-r, r}, 2],
{i, 1, snp, 1}, {j, 1, snp, 1}], 1]}, {n, 1, ni}];
ListPlot[data[[All, 2]], AspectRatio -> Automatic]
For a hexagonal lattice I used the answer from here How to create an hexagonal lattice structure (by rhermans):
unitVectA = {Cos[120 Degree], Sin[120 Degree]}; unitVectB = {1, 0};
data = Table[
{n,
Flatten[Table[(unitVectA j + unitVectB k) + RandomReal[{-0.1, 0.1}, 2],
{j, 1, 5}, {k, Ceiling[j/2], 5 + Ceiling[j/2]}], 1]
}, {n, 1, ni}];
ListPlot[data[[All, 2]], AspectRatio -> Automatic]
How can the calculation of the data
be improved, without using Table
?
data[[1]]
, wherby the first number is the number of the data set followed by the point coordinates placed on the grid. $\endgroup$