'Unable to concatenate the table variables 'Var1' and 'Var2', because their types are cell and double.' why this error is showing?
41 次查看(过去 30 天)
显示 更早的评论
clear all;
clc;
%read X sample
ix1 = readtable("x_sample_01.dat",'ReadVariableNames',false);
x1 = table2array(ix1);
0 个评论
回答(1 个)
Walter Roberson
2023-3-18
Your file contains a mix of text and numeric. What result are you expecting when you ask to convert it to a single array?
5 个评论
Walter Roberson
2023-8-25
I can say that your analysis is incorrect for the situation because I demonstrated a case where table2array() causes exactly the error that the error reports.
Furthermore, in cases where "just numbers are remained" then table2array() will not have any problems. Here is an example in which readtable is removing leading text, leaving only numbers, and you can see that what is left does not cause any problem with table2array()
headerlines = {'heading out to Eden'; 'No more trouble in my body or my mind'};
Var1 = [101; 201];
Var2 = [11; 22];
top = [headerlines, cell(2,1)];
bottom = [num2cell(Var1), num2cell(Var2)];
C = [top; bottom]
writecell(C, 'temp_table.xlsx');
ix1 = readtable('temp_table.xlsx')
x1 = table2array(ix1)
writecell(C, 'temp_table.csv');
dbtype temp_table.csv
Walter Roberson
2023-8-25
The case where there are empty columns get converted to doubles and filled with NaN -- no problem with table2array()
headerlines = {'Var1', 'Var2'};
Var1 = cell(2,1);
Var2 = [11; 22];
top = headerlines;
bottom = [Var1, num2cell(Var2)];
C = [top; bottom]
writecell(C, 'temp_table.xlsx');
ix1 = readtable('temp_table.xlsx')
x1 = table2array(ix1)
writecell(C, 'temp_table.csv');
dbtype temp_table.csv
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!