How do I create a "shared field" in a structure array?

I want to create a field that all structures have access to. I want it this way so that by updating the value in one field the field in the other stuctures automatically adjust so that I do not have to set those individually.
Ex)
Ant(1).age=343;
Ant(1).sharedField=3;
>>Ant(2).age
Ant(2).age=
278
>>Ant(2).sharedField
Ant(2).sharedField=
3

Answers (2)

You will need to use Object Oriented Programming to create a new class that is something like a structure array.
I'm not sure but I think it could be done if you have a class variable and then have one of the properties access a global variable. Then every instance of that class variable would essentially be referencing the same global variable so changing it on one should change it for all others if you write the properties correctly. See " classdef" in the help for further info.

Asked:

on 16 Dec 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!