This is the sort of thing I want to do:
Define class:
classdef Class properties prop end methods function obj = Class(param) if nargin obj.prop = param; end end endend
Then initialize object array like so:
dim = {3,2};param = 1:6;obj_arr(dim{:}) = Class(param)
and get and object array like so:
obj_arr =
2×3 Class array with properties:
prop
obj_arr(1,1).prop =
1
obj_arr(2,1).prop =
2
…
obj_arr(3,2).prop =
6
I have one idea that involves using a static method, but I'm having trouble implementing it, and it feels messy to me.
Also, I know that initalizing the object array like that doesn't work. I guess the idea of initializing an object array is to not pass any parameters and have all of them as clones of one another?
The whole reason for asking this question is because right now I'm doing the preallocation, then using a for loop to intiatiate each object (patient), which takes a lot of time, since I've implemented a particle swarm optimization for each object (patient). I want to be able to have the particle swarm optimization run for all the objects (patients) in the cohort at the same time.
Also, I've tried parfor, and it doesn't help any. I have 27 objects (patients) in my cohort.
Best Answer