- We’ll create a matrix to represent the grid, where each cell represents a node.
- Initialize the first row and first column with 1 (since there’s only one way to reach any cell in the first row or column).
- For each cell (except the first row and first column), the number of ways to reach it is the sum of the ways to reach the cell above it and the cell to its left.
- Finally, the value in the last cell (B) will give you the total number of paths from A to B.
- We can then backtrack to find all the paths.
find all pathbetween 2 node under constraint
1 次查看(过去 30 天)
显示 更早的评论
hey
i want to find all path between A to B ( start from left buttom)
i have tryed to use meshgrid and allpath command without succses
the constraint are the i can go right or up only
also, i need to write code that calculates the probability on each node to go up or right if given that all route is equal probability
i will appreciate hint how to write my code and which commands to use
here is the mesh
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/567744/image.png)
0 个评论
回答(1 个)
Pratik
2024-6-11
Hi Shalom,
From what I can understand, we need to find all possible upward or rightward paths from the bottom-left corner to the top-right corner of a grid, and to calculate the probability of choosing to move right or up at any node, assuming each path is equally likely.
The problem can be approached using dynamic programming,
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!