Dot indexing is not supported for variables of this type. For an array in an object
Afficher commentaires plus anciens
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 commentaires
Cris LaPierre
le 11 Avr 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
le 11 Avr 2023
How are you calling the function eat() ?
Aron
le 11 Avr 2023
Aron
le 11 Avr 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Construct and Work with Object Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!