tags:

views:

319

answers:

2

I made a class and in one of its methods I needed to calculate the distance between two points. So I wrote an ordinary function named "remoteness" to do this for me.

Compilation Error:

At compilation, "remoteness" was determined to be a variable and this variable is uninitialized. "remoteness" is also a function name and previous versions of MATLAB would have called the function.

However, MATLAB 7 forbids the use of the same name in the same context as both a function and a variable.

Error in ==> TRobot>TRobot.makeVisibilityGraph at 58 obj.visiblityGraph(k,k+1) = remoteness(:,obj.VGVertices(k),obj.VGVertices(:,k+1));

I thought the name remoteness might be a name of another function, but when I changed its name to kamran the error persisted. It should be noted that I can use the kamran function (or remoteness) in the command line without any problem.

Command line example:

>> kamran([0,0],[3,4])

ans = 5

The code of the kamran function is in a separate m file.

Code for kamran function:

function dist = kamran(v1,v2)
    dist = sqrt(    (v1(1) - v2(1)) ^2  + (v1(2) - v2(2)) ^2   );

Code example for how kamran function is used:

function obj = makeVisibilityGraph(obj)
          verticesNumber = 0; 
          for num = 1: size(obj.staticObstacle,2)
              verticesNumber = verticesNumber + size(obj.staticObstacle(num).polygon,2);
          end
          % in the below line, 2 is for start and goal vertices
           obj.visibilityGraph = ones(2 + size(obj.VGVertices,2)) * Inf;
           for j=1 : size(obj.staticObstacle,2)
              index = size(obj.VGVertices,2);
              obj.VGVertices = [obj.VGVertices, obj.staticObstacle(j).polygon];
              obj.labelVGVertices = [obj.labelVGVertices, ones(1,size(obj.staticObstacle(j).polygon,2))* j ];
              for k = index+1 : (size(obj.VGVertices,2)-1)
                  obj.visiblityGraph(k,k+1) = kamran(:,obj.VGVertices(k),obj.VGVertices(:,k+1));
              end
%             as the first and last point of a polygon are visible to each
%             other, so set them visible to each other
              obj.visibilityGraph(index+1,size(obj.VGVertices,2)) = ...
                               kamran( obj.VGVertices(:,index+1), obj.VGVertices(:,size(obj.VGVertices,2)));
           end     


end
A: 

I do not know MATLAB but I notice on this line, you are running kamran with what looks like 3 arguments. In all other cases, it is executed with 2 arguments. Maybe there is something to that?

  kamran(:,obj.VGVertices(k),obj.VGVertices(:,k+1));
Frakkle
+4  A: 

You seem to be trying to use kamran as an array:

 kamran(:,obj.VGVertices(k),obj.VGVertices(:,k+1));

Notice the first parameter ":"?

I would bet MATLAB assumes that kamran (as called here) should be a 3-dimensional array, and you are trying to select the subset containing

kamran(all-of-first-index, Nth-of-second, Mth-of-third)

The second invocation of kamran looks right:

kamran( obj.VGVertices(:,index+1), obj.VGVertices(:,size(obj.VGVertices,2))
Jukka Dahlbom
+1 Good catch! This is most likely the source of the error. I only noticed the second call to kamran and couldn't see the problem.
gnovice
Hah. I was on the right track but didn't know what the syntax meant. Good explanation, Jukka.
Frakkle