Hi D W,
As per my understanding the issue you're facing stems from MATLAB's transparency rules within 'spmd', which prevents direct indexing of nested Composite fields. Defining separate variables manually isn't scalable, and using eval is not ideal.
As a workaround, you can nest Composite objects inside another Composite to manage your data effectively. Here's a brief example:
% Create a single Composite to hold all data
AllData_Comp = Composite();
for w = 1:Pool_Size
AllData_Comp{w} = {Data_Struct(1).Comp_Variable{w}, Data_Struct(2).Comp_Variable{w}};
end
The explanation of how it works is that by nesting, each worker has access to all necessary data without manual variable creation and ‘AllData_Comp’ is recognized within ‘spmd’ which avoids transparency errors.
For a better understanding of the above solution, refer to the following MATLAB documentations:
1. Composite Objects: https://www.mathworks.com/help/parallel-computing/composite.html
2. spmd: https://www.mathworks.com/help/parallel-computing/spmd.html
3. parpool: https://www.mathworks.com/help/parallel-computing/parpool.html
