What defines the type of the different variables (eg. cell or double) when you import data (for example from a csv table using uigetfile) ?

조회 수: 22 (최근 30일)
This is the error message i get: Error using table2array (line 27) Cannot concatenate the table variables 'Depth' and 'Cu', because their types are double and cell.
Error in Fullscan_05_17_XRF_CSV (line 7) array = table2array(table(:,1:13));

채택된 답변

Surbhi Pillai
Surbhi Pillai 2018년 9월 24일
While reading csv table, the data type corresponding to different variables depends on the data contained in the table. The strings in the csv table corresponds to cell type whereas the numbers correspond to double after importing csv table into MATLAB.
The error received in your case is due to conversion of a table consisting elements with different data type into an array. An array is a collection of elements of similar data types therefore it is not allowed to concatenate two different data types to form an array.
Consider using 'table2cell' to combine different data type elements to form a cell array. The documentation link to the respective function is given below:
I hope this helps!
  댓글 수: 2
Max Jaquenoud
Max Jaquenoud 2018년 11월 20일
Hi,
First of all, thank yo for your answer. My problem is that the table I have should contain only numbers. However, when I import the csv file into matlab, he thinks that some of these numbers are strings. Is there anyway to convert table types from string to double ?
Best,
Max
Karim botros
Karim botros 2020년 10월 20일
if you are using readtable(),
the readtable function in matlab defines whether a column is a number or string based on the first input.
so my guess is that you might have extra space in the column you have the issue with,
sol:
delete this space in just the first row. and it should work.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by