MATLAB: Dataset array – how can new data be added from a cell array that has some missing elements

assigncell arraydataset arraydeal

I've got numeric data in a cell array that has some empty elements, and I'd like to add this to a dataset array. If I convert to a matrix first, the indexing will be incorrect. I've tried with no avail the customary ways of assignmet to structures:
1) [dataset.prop] = propCellArray{:}; % this only copies 1st cell contents only
[dataset.prop] = deal(propCellArray); % contents remain cell arrays, and any attempt to convert to mat causes indexing problems
Anyone know the correct syntax?
thanks,
Aaron

Best Answer

dataset=struct('prop',propCellArray);
If dataset already exists, use
[dataset.prop]=deal(propCellArray{:})
Okay, don't use dataset as variable name, especially when you are using the dataset() array.
If constructing from new:
propCellArray={1 [] 3 [] 5};
d1=dataset({propCellArray','prop'})
If modifying existing dataset array:
d2=dataset({rand(5,1),'prop'});
idx=cellfun('isempty',propCellArray);
d2.prop(~idx)=[propCellArray{:}]'
Or do processing on propCellArray first and then assign
propCellArray(idx)={0};
d2.prop=[propCellArray{:}]'