CAT error with cell2mat
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
the cyclist
le 13 Mai 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?
Réponses (1)
David Sanchez
le 13 Mai 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 commentaires
José-Luis
le 13 Mai 2013
Modifié(e) : José-Luis
le 13 Mai 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?
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!