필터 지우기
필터 지우기

Table to MATRIX data Conversion

조회 수: 9 (최근 30일)
Sai Gudlur
Sai Gudlur 2024년 4월 1일
댓글: Sai Gudlur 2024년 4월 1일
Hello Everyone,
Before anyone suggests me to look at the other solutions provided, I have already done that.
I have attached the screenshots of the the table I am dealing with and also the error messages when i run the script. If someone can suggest a solution it would be of great help.

채택된 답변

Infinite_king
Infinite_king 2024년 4월 1일
편집: Infinite_king 2024년 4월 1일
Hi Sai Gudlur,
It looks like the error is originating from 'table2array' function call. As per the documentation, 'table2array' function will convert the table data to homogeneous array. However, in this case, it seems one of the column has data type 'cell', because of this 'table2array' was unable to concatenate the columns.
% Table without cell data type
T = table(double([1;2;3]),["str1";"str2";"str3"])
A = table2array(T) % this call will be successful
% the following table contains cell data type in second column
T = table(double([1;2;3]),{"str1";"str2";"str3"})
A = table2array(T) % this call will fail
To resolve this issue, use 'table2cell' function instead of 'table2array'. This will return a cell array instead of homogeneous array.
% Instead use the following function
A = table2cell(T)
For more information, please refer the following documentation,
Hope this is helpful.
  댓글 수: 1
Sai Gudlur
Sai Gudlur 2024년 4월 1일
Incase of Hetrogenoous Data this does the job. Thank you

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by