Search code examples
arraysmatlabcellcell-array

Array of Cells to store cells, without warning


I'm reading in a file(line by line), and returning it as a <1x175 cell>. It's a big file with big computations so I split it into pieces. I understand preallocating will speed up my code, so I made an array to store my data from the file.

warning('off','MATLAB:NonScalarInput');
dataInput = cell(NumOfPartitions,(1:175));      

I've made this work in the past without the Warning: Input arguments must be scalar. but I've forgoten how I did it... This seems to work but I feel like it may not be wise. Here's what it looks like;

dataInput <8,1 cell> =
<1x175 cell>   *<1x175 cell>*  ... <1x175 cell>  

So if i dataInput(2) it will return the second <1x175 cell>


Solution

  • How about something like this:

    dataInput = cell([NumOfPartitions 175]);
    

    This will make an 8x175 cell arrangement. I think that should still be able to contain all of your data... I'm a bit confused though, because you have a reference to both 125 and 175 in your question.

    The reason you're getting a warning is that you're trying to pass an array (1:125) to the cell function. You're effectively asking MATLAB to create a cell array of size (8, 1, 2, 3, 4, ... 125). Which MATLAB guessing is not what you're trying to do. And it's right about that!