Structure Array example as OOP?
16 views (last 30 days)
Show older comments
Hey all,
The structure array as described in the documentation is pretty much exactly what I was looking for to implement in my project.
However, I am trying to approach this in an OOP-way. So far I came up with defining a patient as a class, with all the fields as properties. So far so good, but I can't quite figure out how to combine all these patients in a convenient fashion like it is done in a structure array.
So now I am left wondering whether I am overlooking an obvious feature of OOP, or that I am asking the wrong question i.e. seeing everything as a nail (with OOP as a hammer...)
Any suggestions are much appreciated.
0 Comments
Accepted Answer
Daniel Shub
on 5 Oct 2011
I think you are overlooking a feature of OOP in MATLAB. You should be able to construct an array of your patient class. You haven't posted enough to figure out what you need to do ...
Maybe this will help you see how to use arrays of objects:
Note some of this is stolen from Bert's comments, but the lack of markup in the comments makes it difficult ...
classdef testClass
properties
result = [];
end
methods
function obj = testClass
end
end
end
classdef patientClass
properties
name = '';
test = testClass;
end
methods
function obj = patientClass
end
end
end
patient = patientclass;
patient(1).name = 'John Doe'
patient(1).test(1).result(1) = 3
patient(1).test(1).result(2) = 5
patient(1).test(2).result(1) = 2
patient(2).name = 'Jane Doe'
patient(2).test(1).result(1) = 7
6 Comments
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!