Updating object properties after instantiation

I'm writing a program in which I create a number of objects - Rectangle objects that consist of four objects of class GridPoint (an ordered pair of integers - coordinate points, really), which define the corners of each Rectangle object. Properties of the GridPoint object are:
x, y, type, nXpos = Neighbor; nYpos = Neighbor; nXneg = Neighbor; nYneg = Neighbor;
So, (x,y) are point coordinates, type refers to the category of each point (not important here), and nXpos is the neighbor GridPoint in the positive x direction, and the other names are similarly explained.
My constructor for class GridPoint uses signature: GridPoint(int, int, int). The first value in the parameter list is the x coordinate, the second the y, and the third the type. As for the other properties of the GridPoint objects (Neighbor points), they are attached to each object later.
The problem is, the code keeps breaking with "Not enough input arguments" error. The weird part is that it breaks a few times, I simply delete and then paste back in some code in one of my functions, and it works again until I make substantial enough changes, then it breaks again until I do the same absurd actions to fix it.
Can anyone explain this to me? Thanks!

Answers (1)

What you describe sounds weird. Without more detail it is hard to say what is going on. Does your class look something like this?
>> gp = GridPoint(1,2,3);
>> gp.x=12
gp =
GridPoint with properties:
x: 12
y: 2
type: 3
nXpos: []
nYpos: []
nXneg: []
nYneg: []
where
classdef GridPoint
properties
x
y
type
nXpos % = Neighbor;
nYpos % = Neighbor;
nXneg % = Neighbor;
nYneg % = Neighbor;
end
methods
function this = GridPoint( x, y, type )
this.x = x;
this.y = y;
this.type = type;
end
end
end

4 Comments

jjjjj
jjjjj on 3 Mar 2014
Edited: jjjjj on 3 Mar 2014
Yes, exactly - you've got it; except, I don't comment out the "= Neighbor;" part as you did above.
Whenever I start MATLAB, the program automatically fails until I delete, add, then delete again (a few times) some random code in one of my compiled files (that is automatically generating GridPoint objects). Once the error goes away, it stays away until I make substantial changes to at least one of the files of the program; then I have to go through that whole process to get it to work again.
Neighbor, is that another class? You didn't say.
However, nXpos = GridPoint;, etc, could probably start a "race" creating GridPoint object. Every new GridPoint object will create four new ones. The same if Neighbor creates GridPoint objects.
Yes, each GridPoint object creates four Neighbor objects (each a GridPoint), up to two which could be null. But even if I exclude the function that creates the "neighborhood" of GridPoint objects, the error persists.
This is by design - every point in my grid has up to four other GridPoint objects as neighbors.
  • Yes, but your mesh of grid_point must be finite, fit in memory.
  • My understanding of the behavior is too vague to do anything but guessing.
  • Could you upload an example, which shows the behavior?

Sign in to comment.

Categories

Asked:

on 2 Mar 2014

Commented:

on 3 Mar 2014

Community Treasure Hunt

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

Start Hunting!