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

CAT error with cell2mat

Asked by val on 13 May 2013

I am trying to convert cell data into matrix data, as

-the only method of importing the data (from *.txt) that has worked has been using the wizard. This generates 'cell' data.

-I want to produce a vector plot using the quiver function, which only works with matrix data.

However, conversion using cell2mat gives the following error message:

??? Error using ==> cat
CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 85
            m{n} = cat(1,c{:,n});

Here is the code I used:

>> A=textdata(10:15625,1:12);
>> B=cell2mat(A);

The first line worked, the second delivered the aforementioned error message. I would really appreciate any ideas.

2 Comments

the cyclist on 13 May 2013

It is very hard to diagnose this without seeing the data. I suggest trying to narrow down as small a section of A as possible that will give the error, then examining (and/or posting) those data. For example, does

B = cell2mat(A(1:2,1:2))

give the error?

val on 13 May 2013

The volume of data does appear to be the problem. It worked for the small size you suggested, and as columns of 90. Using 500 elements gave the error message again.

The Data in question are 12 columns and 15625 lines of imported data from a measurement system. The first 10 lines are headers, hence the

A=(10: ...

in the code.

Do you have a suggestion of how to transfer larger amounts of data into matrices than with cell2mat?

val

Tags

Products

No products are associated with this question.

1 Answer

Answer by David Sanchez on 13 May 2013

As Matlab says, you are facing a dimensional non-agreement problem. For example, if you cell is similar to this:

C = {'qqq';'ww';'rrr'};

and you try

M = cell2mat(C)

Matlab will tell you that: Error using cat CAT arguments dimensions are not consistent.

When using cell2mat you have to be really careful with dimensions. Each cell has to contain elements of the same size. 'qqq' is a 3x1 char array, while 'ww' is a 2x1 array, elements not compatible with cell2mat.

2 Comments

val on 13 May 2013

Is there a different way to convert cell data into matrix data? As I am dealing with imported data the content of the cells varies.

José-Luis on 13 May 2013

If the content of the cells vary, how do you want to concatenate them? For instance what should be the results of concatenating 'abcd' and [1 2 3 4 5 6]. Even if the type is the same, the dimensions can be different. How do you concatenate a 20*30 matrix with a scalar?

If what you mean is how to extract data from a cell matrix, then you can use the curly braces:

 your_data = your_cell_mat{whatever_index}; 

Note that you could convert everything to text, separate each row with a return of carriage (becomes tricky matrices). But if you are already worried about speed, then this might not be what you want. Is there anything preventing you importing your data as a text file directly in that case?

David Sanchez

Contact us