dataset array - how can new data be added from a cell array that has some missing elements
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Oleg Komarov
el 29 de Ag. de 2011
% Create sample cell array
propCellArray = num2cell(rand(20,1));
propCellArray(randi(20,3,1)) = {[]};
% Create sample dataset
dtset = dataset({[],'Prop'});
% Index non-empty and replace with NaN
propCellArray(cellfun('isempty',propCellArray)) = {NaN};
dtset.Prop = cat(1,propCellArray{:});
Other ways will give you dtset.Prop as one element containing the whole propCellArray converted to double and by default padded with zeros where it was empty.
1 comentario
Aaron Gruber
el 30 de Ag. de 2011
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!