Dot indexing is not supported for variables of this type. For an array in an object
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
Cris LaPierre
on 11 Apr 2023
Have you gone through the Object-Oriented Programming Onramp? If you are new to OOP, this is a quick, interactive way to learn how to do this in MATLAB.
Walter Roberson
on 11 Apr 2023
How are you calling the function eat() ?
Aron
on 11 Apr 2023
Aron
on 11 Apr 2023
Accepted Answer
More Answers (0)
Categories
Find more on Construct and Work with Object Arrays 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!