Discretize in two dimension

조회 수: 15 (최근 30일)
Alakesh Upadhyaya
Alakesh Upadhyaya 2024년 9월 30일
편집: nick 2024년 10월 1일
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
John D'Errico
John D'Errico 2024년 9월 30일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

nick
nick 2024년 10월 1일
편집: nick 2024년 10월 1일
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.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by