MATLAB: I can’t get around this error “The right hand side of this assignment has too few values to satisfy the left hand side.”

assignmentcellcell arraycell arraysdeletedeletionerrorindexingMATLABscalar

I'm trying to preallocate a 3×2 cell array with each cell containing an array that is 40,000 x 'length'. The problem is that I keep getting this error.
The right hand side of this assignment has too few values to satisfy the left hand side.
I preallocate the initial cell array size 3×2 at the beginning of the script and later at the beginning of the outermost loop I can set the array size because 'length' is the number of files in a folder holding data files. Note the cell array size '3×2' is in fact set by variable inputs from dialogue, this isn't the problem.
%beginning of script
btime=cell(3, 2);
btime(3,2)={0};
Later I'm when I'm trying to store the arrays:
btime{1:3,1:2}={zeros(40000,filelength)};
This ( above ) is what returns the error "The right hand side of this assignment has too few values to satisfy the left hand side."
I have tried the following,
btime{1:3,1:2}=zeros(40000,filelength);
btime{:,:}={zeros(40000,filelength)};
btime{:,:}=zeros(40000,filelength);
btime(:,:)={zeros(40000,filelength)};
btime(:,:)=zeros(40000,filelength);
%This returns a conversion to cell from double error.
btime(1:1+numheads/2, 1:numballs)=zeros(40000,filelength);
If I simply use
btime{3,2}=zeros(40000,filelength);
it works but only stores a 40,000 x 'length' array in cell (3,2). I need it to store to all cells to be truly useful ,and I want to avoid looping because of the inefficiency of loops. I'm trying to optimize some very ugly code not originally made by me.
Something else I want/(may need) to do is erase the contents of each cell without the erasing the cell itself without loops
btime{:,:}=[]; and
btime{:,:}(1:filelength)=[]; and
btime{:,:}(1,1:filelength)=[];
do not work. I receive same error as before or "Scalar cell array indices required in this assignment." 'filelength' is a whole-number double which is used for indexing elsewhere without problems.
__________________________________
I have never fully understood the absolute intricacies of () and {} in matlab except that {} are used in cell arrays and access values and can be treated as the contents of a bucket where () can be treated as the bucket itself and what's inside the bucket. I know about multilevel indexing which isn't a problem here as far as I can tell, nor can it be efficiently used to store such a large array to a cell in my situation.
What gives? How can I accomplish what I want?

Best Answer

Try this (MATLAB 7.0 or later) btime = cell(3,2); [btime{:}] = deal(zeros(40000, filelength));