MATLAB Answers


Array Preallocation

Asked by Trader
on 28 Mar 2012

I am trying to preallocate an array that can be filled with any type of value string, double, int mostly. What am I doing wrong because I'm getting an error:

l = 300;
w = 13;
full_data=cell(l, w);

This is the error:

??? Subscripted assignment dimension mismatch.


on 29 Mar 2012

I should clarify... after I've allocated the array, I try writing to it like this:

counter is just an integer that increments through a loop.

full_data(counter,:) = {...13 values ...}

on 30 Mar 2012

Can you show your {..13 values.. }

on 31 Mar 2012

full_data(counter,:) = {counter current_date current_time position pa bp num_shares entry_price price sma t_band goshort l_band golong profit};

counter = int
current_date = serial num of date mm/dd/yy
current_time = serial num of time HH:MM
position = int
everything else = double

thanks for you help!


No products are associated with this question.

1 Answer

Answer by Thomas
on 28 Mar 2012

your code works correctly and preallocates memory correctly

l = 300;
w = 13;
full_data=cell(l, w);
>> size(full_data)
ans =
        300.00         13.00

Try clearing the variables before you begin.

doc clear

  1 Comment

Matt Tearle
on 28 Mar 2012

Perhaps you have a variable called "cell"...?

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!