Dot indexing is not supported for variables of this type. For an array in an object
5 views (last 30 days)
Show older comments
Hi, i'm trying to make a method in a object which receives an array and the object itself as input arguments and uses a property as indices for the array that is used as input. But I get the prompt that dot indexing is not supported for variables of this type. I have tried this outside of an object so this function should work but it doesn't, it probably has something to do with the self.currenGridCell syntax but I do not understand how I can fix this. I am new to OOP so all or any help is welcome.
classdef Herd
properties
name;
nCows{mustBePositive, mustBeInteger};
currentGridCell(1,2);
end
methods
function newHerd = Herd(name, nCows, currentGridCell)
if nargin == 3 % if all three arguments (r, p, a) are given to the Constructor
newHerd.name = name;
newHerd.nCows = nCows;
newHerd.currentGridCell = currentGridCell;
end
end
function grasslands = eat(grasslands, self)
grasslands(self.currentGridCell(1,1), self.currentGridCell(1,2)) = grasslands(self.currentGridCell(1,1), self.currentGridCell(1,2)) - (self.nCows*30);
end
end
end
5 Comments
Accepted Answer
Walter Roberson
on 11 Apr 2023
When you use an object method using dot syntax on an object, then the object is always passed as the first parameter to the method. Your code is expecting it to be passed as the second parameter to the method.
More Answers (0)
See Also
Categories
Find more on Performance and Memory 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!