Borrar filtros
Borrar filtros

I have the error when calling function: Check for incorrect argument data type or missing argument in call to function 'calculate​_distance_​sqr'.

2 visualizaciones (últimos 30 días)
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!!
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 comentarios
Duc Pham Minh
Duc Pham Minh el 24 de Ag. de 2023
Thanks for your attention. In my snipping figure, when I run file 'runcode' file, the code performs the RRTSS Algorithm. In methods of class RRTStarSmart, I have a function 'calculate_distance_sqr' calculating the ddisstance of 2 node (both are the instances of the Node class I show above). But I have some problem when calling this function 'calculate_distance_sqr'. The lines of that those cause errors may be in the 'Near' function or in 'calculate_distance_sqr' function in the snippet above.
Duc Pham Minh
Duc Pham Minh el 24 de Ag. de 2023
for a closer checking, you can see in my zip.file in my reply to Mr.Rohit above. Thanks for your help

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Dynamic System Models en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by