因此,我有一个包含数千个文件的文件夹,所有文件都有系统名称。我希望用户能够选择一个文件夹,之后所有文件名都从列表(单元格数组)转换为某种树结构。然而,实施如何在Matlab中存储这是我卡住的地方。这是我迄今所做的:从系统字符串(文件名)列表创建部分字符串的树
folder = uigetdir;
files = dir([folder '\*.nii']);
nfiles = length(files);
filez = cell(nfiles, 1);
for file = 1:nfiles
filez(file,:) = cellstr(files(file).name);
end
files = filez;
chars = zeros(nfiles, 1);
for file = 1:nfiles
chars(file) = length(files{file});
end
filez = files;
names = struct;
for file = 1:nfiles
curfil = filez{file};
depth = 0;
for curchar = 1:chars(file)
if curchar == 1
curmatch = strmatch(curfil(1:curchar), filez);
prevmatch = curmatch;
else
prevmatch = curmatch;
curmatch = strmatch(curfil(1:curchar), filez);
end
if length(curmatch) ~= length(prevmatch)
newnamepart = curfil(1:curchar-1);
newstructnamepart = ['X' newnamepart]; %This I did because fieldnames must start with characters
%This is where I dont know how to go on...
end
end
end
因此,对于每一个文件名我检查从其他文件名具有相同字符串开头的名字开始各部分的字符串。如果这种变化我回去一个字符,这应该是我的第一个节点在树中。但是我不知道如何创建这样一棵树。结构看起来最像我这样,但我不知道如何创建这个结构,但也许有另一种方式?
你能画一张图吗,即使在一张纸上并发布扫描图吗? 另外,你能否提供一个简单的树如何在特定文件名上分支的例子? – Oleg