This answer was helpful: Coder error - Directly accessing field or property of nonscalar struct or object not supported for code generation - MATLAB Answers - MATLAB Central
It led to the following code which successfully worked through codegen. I'd still like to see if anyone has any insight into better ways to do this though. Thanks!
% This script calls the cellTform function and tries to generate code
% build the input struct array
StructIn(1).t = {magic(3)};
StructIn(2).t = {magic(3)};
StructIn(3).t = {magic(3)};
StructIn(4).t = {magic(3)};
StructIn(5).t = {magic(3)};
StructIn(6).t = {magic(3)};
% build the sorting index array
SortingInd = [1;3;2;5];
tic
cellOut = cellTform(StructIn,SortingInd)
toc
ARGS{1} = coder.typeof(StructIn,[1 Inf],[false true]);
ARGS{2} = coder.typeof(SortingInd,[Inf 1],[true false]);
codegen cellTform -args ARGS
tic
cellOutMex = cellTform_mex(StructIn,SortingInd)
toc
function cellOut = cellTform(arrayStructIn,SortingIndexIn)
%#codegen
% This function accepts an array of strcuts that contain a {1x1} cell of
% [3x3] doubles and an array if indices that need to be extracted from the
% array of structs and put into the output cell of
% {1xlength(SortingIndexIn)}.
% Inputs:
% arrayStructIn = array of structs that contain a {1x1} cell of [3x3]
% doubles = arrayStructIn(N).t{1}[3x3]
% SortingIndexIn = column vector in indices that must be extracted from
% arrayStructIn [Mx1], not sorted and output cell must retain this order
% Output:
% cellOut = cell array {1xM} of the extracted cells of arrayStructIn
% first part - transform the struct array
NArrayStruct = size(arrayStructIn,2);
celldum = cell(1,NArrayStruct);
for cnt = 1:NArrayStruct
celldum{cnt} = arrayStructIn(cnt).t{:};
end
% seconde part - extract the cells I want
Nsort = length(SortingIndexIn);
cellOut = cell(1,Nsort);
for cnt = 1:Nsort
cellOut{cnt} = celldum{SortingIndexIn(cnt)};
end
end
