Preallocation Problem in for loop
이전 댓글 표시
I have a function which takes a cell array "c" and checks for the length of x and a part of the code is:
str = [];
for i=1:size(c,1)
str = [str;extractBetween( func2str(c{i,1}),'x(',')')];
end
I get the warning that str is not preallocated.
%Examples, how str looks like
c = cell(1,1);
c{1} = @(x) 10*x(1)-x(2)^2
%here str would be a 5 x 1 cell array :
{'1'}
{'2'}
%or:
c = cell(2,1);
c{1} = @(x) 10*x(1)-x(1)^2
c{2} = @(x) x(1)^2+4*x(2);
%here str would be a 4 x 1 cell array :
{'1'}
{'2'}
{'1'}
{'2'}
Would it be possible to preallocate str?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!