Question about extracting a structure field using eval
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ano
el 16 de Nov. de 2017
hi! I am extracting the fields of a structure using the following code
names = fieldnames(BD);
for ii = 1: length(names)
eval([names{ii} '=BD.' names{ii}]);
end
and it works but I get all the extracted arrays and data shown in the commend window also, any suggestion how to avoid this ?! thank you!
Respuesta aceptada
Stephen23
el 16 de Nov. de 2017
Editada: Stephen23
el 16 de Nov. de 2017
Do NOT use eval for such trivial code. This way of accessing structure fields has been obsolete for more than ten years, as you will learn when you read the MATLAB blogs.
names = fieldnames(BD);
for ii = 1:numel(names)
names{ii} = BD.(names{ii});
end
out = struct2cell(BD);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Variables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!