how can i make a parent - children hierarchy
이전 댓글 표시
Hello
i have two column one is number of hiarachy the second is the name of that hiarachy like this :

can you help make a code that will generate what is manually wrote in the third column , note that the file is large and contain long WBS path like this (2.2.3.5.4.5.7)
Regards
댓글 수: 3
dpb
2024년 8월 3일
Attach at least a representative sample of the file.
Clarify what it is you really want the return to be; readtable will return the content of the file for each column as string data; what is the intent once you've read it?
Muhannad AL-hazmi
2024년 8월 4일
dpb
2024년 8월 4일
You forgot to attach a sample file...
답변 (1개)
Here's some logic that should do it. Adjust as necessary for your actual file.
% an example table that might be similar to what you get when you
% readtable() your file:
WBS_Path = {'2';'2.1';'2.1.1'};
WBS_Name = {'SCOPE OF WORK';'KEY MILESTONES';'CONTRACTUAL MILESTONES'};
T = table(WBS_Path,WBS_Name)
% construct the third column from the first two:
N = cellfun(@(p)nnz(p=='.')+1,T.WBS_Path);
C = arrayfun(@(n)repmat({''},1,n),N,'UniformOutput',false);
for ii = 1:size(T,1)
idx = find(startsWith(T.WBS_Path,T.WBS_Path{ii}));
for jj = 1:numel(idx)
C{idx(jj)}(N(ii)) = T.WBS_Name(ii);
end
end
T.WBS_Full_Path_Name = cellfun(@(c)strjoin(c,' > '),C,'UniformOutput',false)
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!