フィルターのクリア

Question about extracting a structure field using eval

11 ビュー (過去 30 日間)
Ano
Ano 2017 年 11 月 16 日
編集済み: Stephen23 2017 年 11 月 16 日
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!

採用された回答

Stephen23
Stephen23 2017 年 11 月 16 日
編集済み: Stephen23 2017 年 11 月 16 日
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.
Use dynamic fieldnames instead:
names = fieldnames(BD);
for ii = 1:numel(names)
names{ii} = BD.(names{ii});
end
Or learn how to use MATLAB efficiently and use struct2cell:
out = struct2cell(BD);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by