Hi. I have different data types (text and numeric) within the array range that I read from the input table. How can I avoid the error of using table2array and cell2mat?

2 ビュー (過去 30 日間)
kahhoong kok
kahhoong kok 2022 年 11 月 4 日
回答済み: Lei Hou 2022 年 11 月 18 日
xlFiles = dir('*.xlsx');
N = length(xlFiles);
Tmat = cell(N,1) ;
for i = 1:N
thisFile = xlFiles(i).name;
T = readtable(thisFile,'Range','a3:u29','ReadVariableNames',false);
Tmat{i} = table2array(T);
end
Tmat = cell2mat(Tmat) ;
xlswrite('allmodel2010to2039.xlsx',Tmat);

回答 (2 件)

Cris LaPierre
Cris LaPierre 2022 年 11 月 4 日
Arrays and matrices can only contain data of the same data type. You need to convert all your data to the same data type before you can put it together in an array or matrix.
Why not just keep your data in a table? Since the only reason you are converting appears to be to use xlswrite, consider using writetable instead.

Lei Hou
Lei Hou 2022 年 11 月 18 日
Hi,
Please check whether table2cell meets your need.
>> t = readtable('Best NST models(1534002).xlsx');
>> table2cell(t)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by