필터 지우기
필터 지우기

editing inside cells array

조회 수: 1 (최근 30일)
Jwana
Jwana 2012년 11월 7일
I have this cells array which is came from a mat lab code that generates dewey IDs:
POT1 =
'a0' [] [] []
'a0' 'c0' [] []
'a0' 'b0' [] []
'a0' 'c1' [] []
'a0' 'd0' [] []
'a0' 'c0' 'd1' []
'a0' 'b0' 'd2' []
'a0' 'd0' 'd3' []
'a0' 'd0' 'c2' []
'a0' 'd0' 'b1' []
'a0' 'd0' 'd4' []
'a0' 'c1' 'c3' []
'a0' 'c1' 'b2' []
'a0' 'c1' 'c3' 'd5'
'a0' 'c1' 'b2' 'd6'
'a0' 'd0' 'b1' 'd7'
'a0' 'd0' 'c2' 'd8'
note that column 1 is parent of column 2 and column 2 is paret of column 3..etc
so I want to build a code that gives the full name of each cell as follow:
POT1 =
a0 [] [] []
a0 a0.c0 [] []
a0 a0.b0 [] []
a0 a0.c1 [] []
a0 a0.d0 [] []
a0 a0.c0 a0.c0.d1 []
a0 a0.b0 a0.b0.d2 []
a0 a0.d0 a0.d0.d3 []
a0 a0.d0 a0.d0.c2 []
a0 a0.d0 a0.d0.b1 []
.
.
.
.
The code which I build is not complete and gives me :" Index exceeds matrix dimensions" error :
for i=1:length(POT1)
for j=3:size(POT1,2)
if ~isempty(POT1{i,j})
POT1{i,j}=[POT1{i,j-2} POT1{i,j-1} POT1{i,j}];
end
end
end
POT1

채택된 답변

Grzegorz Knor
Grzegorz Knor 2012년 11월 7일
You can try this code:
for i=1:size(POT1,1)
for j=2:size(POT1,2)
if ~isempty(POT1{i,j})
POT1{i,j}=strcat(POT1{i,j-1}, '.', POT1{i,j});
end
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by