I have the error when calling function: Check for incorrect argument data type or missing argument in call to function 'calculate_distance_sqr'.
2 views (last 30 days)
Show older comments
In my MATLAB folder, I have class Node, and my class RRTStarSmart have some methods need the instances of the Node class as variables. My function 'calculate_distance_sqr' will calculate the distance between 2 node and I define this function as the helper function. When I call this 'calculate_distance_sqr' function, I meet the error: Check for incorrect argument data type or missing argument in call to function 'calculate_distance_sqr'. Both classes are the value classes. I think it has a trouble when I acess to the properties of class Node, but I can't see the solution. Thanks for your help!!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1463662/image.png)
This is my class Node:
classdef Node
properties
x
y
parent
end
methods
function obj = Node(n)
obj.x = n(1);
obj.y = n(2);
obj.parent = [];
end
end
end
And this is a snippet of class RRTStarSmart that occur the error:
function X_near = Near(obj, nodelist, node)
n = length(nodelist) + 1;
r = 50 * sqrt((log(n) / n));
% Calculate squared distances using the helper function
dist_table = arrayfun(@(nd) calculate_distance_sqr(node, nd), nodelist);
% Find nodes in the neighborhood based on the squared distance and collision check
X_near = nodelist(dist_table <= r^2 & ~obj.is_collision(node, nodelist));
end
% Helper function to calculate squared distance between two nodes
function distance_sqr = calculate_distance_sqr(obj,node1, node2)
dx = node2.x - node1.x;
dy = node2.y - node1.y;
distance_sqr = dx^2 + dy^2;
end
thanks a lot !!
5 Comments
Answers (0)
See Also
Categories
Find more on Dynamic System Models 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!