vertcat on a cell array and a double array

조회 수: 5 (최근 30일)
Cary
Cary 2014년 7월 15일
답변: Cary 2014년 7월 15일
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
José-Luis
José-Luis 2014년 7월 15일
It might mean that not all the strings in the cell array have the same length and therefore you cannot concatenate them.

댓글을 달려면 로그인하십시오.

답변 (2개)

Amy Haskins
Amy Haskins 2014년 7월 15일
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 2014년 7월 15일
many thanks!

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by