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 CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by