Discretize in two dimension

12 visualizaciones (últimos 30 días)
Alakesh Upadhyaya
Alakesh Upadhyaya el 30 de Sept. de 2024
Editada: nick el 1 de Oct. de 2024
I have data points or data co-ordinates in 2D. Let's say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated.
  1 comentario
John D'Errico
John D'Errico el 30 de Sept. de 2024
Far too vague to have an answer. I think MAYBE all you need to do us to use round, to move your x and y coordinates to the grid points. If you want a better answer than that, then you need to possibly give an example. Or be far more clear aout your goal.

Iniciar sesión para comentar.

Respuestas (1)

nick
nick el 1 de Oct. de 2024
Editada: nick el 1 de Oct. de 2024
Hi Alakesh,
I understand that you want to compute the probability flux between each transition in a 2D space for a random trajectory that is discretized with equal grid size in the X and Y directions. To discretize a 2D trajectory into a grid and calculate the probability fluxes between the grid cells, you can use the 'histcounts2' function to create a 2D histogram of the data points to discretize the space.
Then, you can calculate the transitions between grid cells over time by looping through transitions between bins. Here's a sample MATLAB code that demonstrates the same:
x= randn(10000,1);
y= randn(10000,1);
numBinsX = 10;
numBinsY = 10;
% Define edges for the bins
xEdges = linspace(min(x), max(x), numBinsX+1);
yEdges = linspace(min(y), max(y), numBinsY+1);
[N, ~, ~, binX, binY] = histcounts2(x, y, xEdges, yEdges);
% Initialize transition matrix
transitions = zeros(numBinsX, numBinsY, numBinsX, numBinsY);
% Calculate transitions
for t = 1:length(x)-1
currentBinX = binX(t);
currentBinY = binY(t);
nextBinX = binX(t+1);
nextBinY = binY(t+1);
% Ensure valid bins before counting transition
if currentBinX > 0 && currentBinY > 0 && nextBinX > 0 && nextBinY > 0
transitions(currentBinX, currentBinY, nextBinX, nextBinY) = ...
transitions(currentBinX, currentBinY, nextBinX, nextBinY) + 1;
end
end
% Initialize probability flux matrix
probabilityFlux = zeros(numBinsX, numBinsY, numBinsX, numBinsY);
% Calculate probability flux
for i = 1:numBinsX
for j = 1:numBinsY
totalTransitions = sum(sum(transitions(i, j, :, :)));
if totalTransitions > 0
probabilityFlux(i, j, :, :) = transitions(i, j, :, :) / totalTransitions;
end
end
end
You can refer to the following documentation to learn more about 'histcounts2' function ;
Hope this helps.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by