I have a class object, where one of the properties of the object is an array of objects of a different class. So ClassA has a property called 'population' which is an array of ClassB objects. ClassB has a property called 'fitness'. I want to find the element in the 'population' that has the highest fitness.
classdef ClassA < handle
function obj = ClassA(target, popSize)
n = 1;
while n <= popSize
obj.population(n) = ClassB(target);
n = n + 1;
classdef ClassB < handle
The ClassA constructor works. I'm able to fill the array with ClassB objects, each of them having a unique value for ClassB.fitness. I've tried the max() function, as seen below:
target = 'Hello!';
popSize = 100;
obj = Population(target,popSize);
[M, I] = max(obj.population.fitness)
But, to no avail. Any suggestions on how to find the max fitness without using a loop?