フィルターのクリア

.MAT file with multiple tabs/sheets

3 ビュー (過去 30 日間)
Saeid
Saeid 2023 年 6 月 19 日
コメント済み: Walter Roberson 2023 年 6 月 19 日
I would like to copy the contents of a multi-sheet excel file into a .mat file. Is it possible to have a multi-sheet .MAT file? If not, what would be the alternative (other than having a single .mat file for each excel sheet)?
  2 件のコメント
Stephen23
Stephen23 2023 年 6 月 19 日
編集済み: Stephen23 2023 年 6 月 19 日
"Is it possible to have a multi-sheet .MAT file?"
A MAT file is just a container, you can save anything in it: the MAT file binary format lets you store any number of arrays of any MATLAB class of any size. The simplest apporoach would be to import them into one cell array and SAVE that.
A MAT file is not one matrix.
Walter Roberson
Walter Roberson 2023 年 6 月 19 日
Is it possible to have a multi-sheet .MAT file?
No
MAT files do not have the concept of sheets. You can use a structured datatype, such as struct (as @Ive J shows), or as cell arrays, or as a table containing tables, or various other possibilities.

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

回答 (1 件)

Ive J
Ive J 2023 年 6 月 19 日
編集済み: Ive J 2023 年 6 月 19 日
you can do something like this, and write each sheet to fields of a structure:
snames = sheetnames("myfile.xlsx");
out = struct;
for k = 1:numel(snames)
fi = matlab.lang.makeValidName(snames(k));
out.(fi) = readtable("myfile.xlsx", Sheet=snames(k), VariableNamingRule="preserve");
end
save("myfile.mat", "out")

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by