'Unable to concatenate the table variables 'Var1' and 'Var2', because their types are cell and double.' why this error is showing?

41 ビュー (過去 30 日間)
Rajkumar
Rajkumar 2023 年 3 月 18 日
コメント済み: F 2024 年 9 月 13 日
clear all;
clc;
%read X sample
ix1 = readtable("x_sample_01.dat",'ReadVariableNames',false);
x1 = table2array(ix1);

回答 (1 件)

Walter Roberson
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?
  6 件のコメント
Walter Roberson
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]
C = 3×2 cell array
{'Var1' } {'Var2'} {0×0 double} {[ 11]} {0×0 double} {[ 22]}
writecell(C, 'temp_table.xlsx');
ix1 = readtable('temp_table.xlsx')
ix1 = 2×2 table
Var1 Var2 ____ ____ NaN 11 NaN 22
x1 = table2array(ix1)
x1 = 2×2
NaN 11 NaN 22
writecell(C, 'temp_table.csv');
dbtype temp_table.csv
1 Var1,Var2 2 ,11 3 ,22
F
F 2024 年 9 月 13 日
You can use readcell. Thats all.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMeasurements and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by