필터 지우기
필터 지우기

Initializing a char structure for a loop

조회 수: 7 (최근 30일)
Jacob Matthews
Jacob Matthews 2015년 5월 8일
댓글: Jacob Matthews 2015년 5월 8일
I am building up a char structure of file paths and names in a large for loop in the form
list=[]
for i =1:n
stuff
file = something
list=char(list,file)
end
My problem is that the first row of list is empty doing it like this. Is there a way to initialize a char array without creating an empty row? I can remove it afterwards but that seems messy.
And in case there is a generally better method of compiling file paths, I'm working within a pipeline that requires me to construct this.
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 8일
list = cell(n, 1);
for i = 1 : n
stuff
list{i} = file;
end
list = char(list);
  댓글 수: 1
Jacob Matthews
Jacob Matthews 2015년 5월 8일
Thanks, I've been using list = list(2:end,:) after my loop, so same number of lines, but I imagine memory management is better your way. I was just hoping there was a different method of initialization for the list that wouldn't stack when char'd.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by