필터 지우기
필터 지우기

Creating cell array of strings in a loop

조회 수: 4 (최근 30일)
Craig
Craig 2012년 12월 4일
Hi all,
I have a few lines as such:
timeStrings = cell(1,entries_per_variable);
for o = 1:1:entries_per_variable
timeStrings{o,1} = [num2str(TimeValue(3,o),'%02i'),'/', num2str(TimeValue(2,o),'%02i'),'/', num2str(TimeValue(1,o),'%04i'),...
' ',num2str(TimeValue(4,o),'%02i'),':',num2str(TimeValue(5,o),'%02i'),':',num2str(TimeValue(6,o),'%02i')]; %this be a column vector
end
It basically converts some values in TimeValue to strings, adds some spaces and slashes using the [] string catenation method and puts them in a new cell array.
I'm running out of memory less than 50 entries in! As you can see the memory is preallocated so I can't fathom why.
Best regards,
Craig B
  댓글 수: 1
Jos (10584)
Jos (10584) 2012년 12월 4일
... you pre-allocate a 1xN array, but intend to fill a Nx1 array, ending up filling a NxN array ... (This should not give you memory problems though)
I also suggest you take a look at SPRINTF.

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

채택된 답변

Craig
Craig 2012년 12월 4일
Ok I got the dimensions of the preallocation wrong. Should have been timeStrings = cell(entries_per_variable,1);
Best regards,
Craig

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by