I'm working with nested classes for Object Oriented Programming (OOP) and trying to find a cleaner way of doing things. For example, the following code is a function of a class Attacker which is a pain to read where Attacker has a property filtered_database which is a class which has vulns which has profile which has props which has scaled_value. Embedded classes like this are the norm for OOP, but using an indexed iteration scheme is just not nice and when you have 1000 lines of code the migranes set in.
% Loop through each vulnerability
for i=1:length(obj.filtered_database.vulns) temp_profile = obj.filtered_database.vulns(i).profile; % Scale each property
for j=1:length(temp_profile.props) scaled_val = obj.ScaleProperty(temp_profile.props(j)); obj.filtered_database.vulns(i).profile.props(j).scaled_value = scaled_val; endend
So I'm trying to use the more functional component of the for loop. Take the example:
People = {'Joe', 'Bill', 'Ted'}for person = People person = strcat(person,' Foo');endPeople
If we were in python, person would be recognized as a linked part of the People object within the for-loop, meaning any changes I make to person would be reflected in People after completion of the for-loop, but this is not the case in Matlab. Now, in order to update the values in People, I need some sort of counter to keep track of which item in People I'm looking at. Is there a standard way of modifying the value in People in the loop as you would in Python without a counter? Any help would be appreciated.
Best Answer