1
votes

MATLAB has a few functions for building one dimensional grids (linspace, logspace, grid, ets). I need a function for generating an irregular one-dimensional grid with certain points distribution density.

Let's say: nonelinspace(a, b, N, @distr), where a, b is the interval, N - the number of points and distr is a function of points density (polynomial, Gaussian, hyperbolic, ...).

Is this possible to do in MATLAB?

Additional remarks: we have an interval [a, b] divided by N = 1000 points: linspace(a, b, N); set number of cells (n = 100) and some density distribution function: distr = @(o) exp(-1e-3*((0:o) - .5*o).^2) like this. The expression N*distr(n)/sum(distr(n)) (or round(N*distr(n)/sum(distr(n)))) gives us number of points in every cell. And we need distribute the points EVENTLY along whole interval [a, b].

1
does that mean the a and b are always included values or just limits for that distribution ?bla

1 Answers

1
votes

I'm not sure about how you thought of the sampling of the grid that you want to produce, so I figured a random sampling according to the distribution is what you meant (please correct me if I've misunderstood).

So you actually do have some built in matlab function for that, for example, a uniformly random distribution in the interval [a b] of N points will be

dist = (b-a).*rand(N,1) + a;

same tricks can be applied for normal distribution (or gaussian) using randn, or Posisson dist using poissrnd etc (see more options here and here). Other cases can use the unifrom dist rule with a twist of the specific case.