How to reduce the time taken for the loop that finds all the sub structures which are of different depths and include last sub structures which are not structures

1 回表示 (過去 30 日間)
data_file=load(fname{1,indx}); %%%% Importing data file
NAMES = cellfun(@(x) strcat('data_file.',x),fieldnames(data_file),'UniformOutput',false) ;
for i=1:10000; %%%% loop to get all the structures
if isstruct(eval(NAMES{i,1})) >= 1
new_name=fieldnames(eval(NAMES{i,1}));
for k=1:length(fieldnames(eval(NAMES{i,1})));
new_NAMES(k,1)= cellfun(@(x) strcat([NAMES{i,1},'.'],x),cellstr(new_name{k,1}),'UniformOutput',false);
end
elseif isstruct(eval(NAMES{i,1})) < 1
end
NAMES=[NAMES; new_NAMES];
end
NAMES=unique(NAMES);
for i=1:10000; %%%% loop to get sub structures names if the last list of structures that are charecters or double
if isstruct(eval(NAMES{i,1})) < 1
new_name=cellstr(NAMES{i,1});
for k=1:length(NAMES{i,1})
new_NAMES= new_name;
end
elseif isstruct(eval(NAMES{i,1})) >= 1
new_name=fieldnames(eval(NAMES{i,1}));
for k=1:length(fieldnames(eval(NAMES{i,1})));
new_NAMES(k,1)= cellfun(@(x) strcat([NAMES{i,1},'.'],x),cellstr(new_name{k,1}),'UniformOutput',false);
end
end
NAMES=[NAMES; new_NAMES];
end
NAMES=unique(NAMES);

回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by