Finding the output of this command
1 view (last 30 days)
Show older comments
The variable 'state' is a 60 x 2 matrix.
xdiv = (0.55-(-1.5))/10;
x = -1.5:xdiv:0.5;
What does the command
[d s] = min(dist(statelist,x'))
do?
This is a part of the function that is labeled 'discretized states'. Originally the state x is continuous in the interval [-1.5, 0.55].
0 Comments
Answers (1)
Walter Roberson
on 20 Dec 2015
dist() is a distance function. For each state in statelist, the distance to all of the x is computed. Then the min() finds the minimum of those distances, and so is finding the closest x to each state in the statelist. The d is returning how far it is from an x and the s is returning the index of the x.
Except that it constructs the x slightly wrong due to floating point roundoff. It would be better if it had used
x = linspace(-1.5, 0.55, 11);
Does the code actually need the distance from the nearest x? Or does it just need to know which is the nearest x? If it just needs to know which is the nearest x then
nearest_x = round((statelist-(-1.5))/xdiv) * xdiv + (-1.5);
2 Comments
Walter Roberson
on 20 Dec 2015
A function that just needs to discretize over a uniformly spaced array can use the nearest_x that I showed.
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!