MATLAB Answers

How to join/merge all sub tables into 1 table?

5 ビュー (過去 30 日間)
Ergün AKGÜN
Ergün AKGÜN 2018 年 3 月 26 日
コメント済み: Guillaume 2018 年 3 月 26 日
Hi;
i have a table (S1) and it contains 4041 tables into. Sub tables are all text. I want to merge them to a single table or cell. I don't know how to merge them..
(all tables have text data)

  4 件のコメント

表示 1 件の古いコメント
Ergün AKGÜN
Ergün AKGÜN 2018 年 3 月 26 日
Hi Guillauma,
No; Actually, it's not a variable name. I import these tables from excel spreedsheets and i guess i made a mistake. Matlab gets the first lines as variable name. Now we have a new problem :)
Guillaume
Guillaume 2018 年 3 月 26 日
That new problem is easily fixed. But at the same time, we can fix the import so that it's the right format directly. The simplest thing would be for you to show your import code.
Ergün AKGÜN
Ergün AKGÜN 2018 年 3 月 26 日
Here is my code;
[~,SheetNames] = xlsfinfo('a.xlsx')
nSheets = length(SheetNames)
for iSheet = 1:nSheets
Name = SheetNames{iSheet};
Data = readtable('a.xlsx','Sheet',Name) ;
S(iSheet).Name = Name;
S(iSheet).Data = Data;
end

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

採用された回答

Guillaume
Guillaume 2018 年 3 月 26 日
編集済み: Guillaume 2018 年 3 月 26 日
[~,SheetNames] = xlsfinfo('a.xlsx');
nSheets = numel(SheetNames);
SheetContents = cell(size(SheetNames));
for iSheet = 1:nSheets
Name = SheetNames{iSheet};
SheetContents{iSheet} = readtable('a.xlsx','Sheet',Name, 'ReadVariableNames', false);
end
SheetContents = vertcat(SheetContents{:});

  2 件のコメント

Ergün AKGÜN
Ergün AKGÜN 2018 年 3 月 26 日
The code lists the table numbers, but not their contents.And here is the warning.
Guillaume
Guillaume 2018 年 3 月 26 日
The code lists the table numbers
That bit is your own code and is the output of xlsfinfo that is displayed because you didn't end the line with a semicolon.
As for the error, that's a simple typo. I wrote sheetNames instead of SheetNames.
I've fixed both issues.

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

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by