Updating structure data within a containers.map.
Afficher commentaires plus anciens
Hi, I just got started on a pred-prey simulation. I started out with structures two preys and I put them in a map. Now I want to make their age (starting with the prey's) increase over time. When I run my code I get the following error in the second for loop: only one level of indexing is supported by a containers.Map. Even when I try to change the age outside of the loop I get the same error. Can anyone help me out? I'm new to MATLAB...
numDays = 100;
preyMap = containers.Map('KeyType', 'double', 'ValueType', 'any');
prey1 = struct('x', 2, 'y', 2, 'age', 365, 'lastbirth', 100);
preyMap(1) = prey1;
prey2 = struct('x', 3, 'y', 3, 'age', 365, 'lastbirth', 100);
preyMap(2) = prey2;
for p = 1:length(preyMap)
disp(preyMap(p).age)
for t = [1:numDays]
preyMap(p).age = preyMap(p).age + t
disp(preyMap(p).age)
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Scripts 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!