Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

what is wrong with this simple code?

Asked by Sergio

Sergio (view profile)

on 4 Jul 2013

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)



m =

      100000           1           0

??? Attempted to access days(1); index out of bounds because numel(days)=0.



Sergio (view profile)


No products are associated with this question.

1 Answer

Answer by the cyclist

the cyclist (view profile)

on 4 Jul 2013
Accepted answer

Preallocate like this instead

days = zeros(100000,1);


the cyclist

the cyclist (view profile)

Contact us