vertcat on a cell array and a double array

6 visualizaciones (últimos 30 días)
Cary
Cary el 15 de Jul. de 2014
Respondida: Cary el 15 de Jul. de 2014
I have a 1x601 cell array containing text and a 1019x601 double matrix. I am trying to merge the arrays using vertcat but I get "dimensions of matrices being concatenated are not consistent." Theoretically I should get a matrix that is 1020x601. What am I doing wrong? Thanks.
  1 comentario
José-Luis
José-Luis el 15 de Jul. de 2014
It might mean that not all the strings in the cell array have the same length and therefore you cannot concatenate them.

Iniciar sesión para comentar.

Respuestas (2)

Amy Haskins
Amy Haskins el 15 de Jul. de 2014
You need to work with cell arrays in order to support mixed numeric and string data. To use vertcat, convert the double matrix to a cell first.
Example:
A = rand(5);
B = {'apple','pear','banana','orange','peach'};
vertcat(num2cell(A),B)

Cary
Cary el 15 de Jul. de 2014
many thanks!

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by