How to convert a cell array of structures to array of structures
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ysz
el 21 de Dic. de 2016
Comentada: ysz
el 22 de Dic. de 2016
nodeinfo = searchNode(neo4jconn, 'Comment')
nodeinfo.NodeData contains node data. It has a property key 'text'
>> nodeinfo.NodeData{1}.text
ans =
blahblah
Please suggest a better than for loop:
s = size(nodeinfo.NodeData, 1);
for i = 1:s
comments(i).text = nodeinfo.NodeData{i}.text;
end
For example to collect text of all comments is now one-liner
text = [comments.text]
How can a cell array of structures be vectorized like that?
0 comentarios
Respuesta aceptada
Guillaume
el 21 de Dic. de 2016
As long as the structures in the cells have all the same fields and that these structures in the cells are either scalar or arrays with the same number of rows:
nodedata = [nodeinfo.NodeData{:}];
%or
nodedata = cell2mat(nodeinfo.NodeData);
Más respuestas (1)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!