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.

*No products are associated with this question.*

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.

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?

Opportunities for recent engineering grads.

## 2 Comments

## the cyclist (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75591#comment_148643

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

give the error?

## val (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75591#comment_148647

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

in the code.

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