필터 지우기
필터 지우기

what is wrong with this simple code?

조회 수: 1 (최근 30일)
Sergio
Sergio 2013년 7월 4일
Hi I am trying to create an empty array so that I can add elements to it concatenating them. This avoid the large time it takes if you dont give it a size previous the for loop, as it has to change its size at every iteration. This is the code:
>> days=double.empty(100000,1,0); m=size(days); m
for k=2:numel(UntitledCase_Temp)
days(k)=(UntitledTime(k)-UntitledTime(k-1))/24*3600+days(k-1);
end;
m =
100000 1 0
??? Attempted to access days(1); index out of bounds because numel(days)=0.

채택된 답변

the cyclist
the cyclist 2013년 7월 4일
Preallocate like this instead
days = zeros(100000,1);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by