フィルターのクリア

Readtable importing variables from wrong sheet

1 回表示 (過去 30 日間)
Andrea Vezzoli
Andrea Vezzoli 2023 年 11 月 29 日
編集済み: Stephen23 2023 年 11 月 29 日
Hello everyone, I am facing a weird issue with readtable that I have never seen before. The code I am using is the following:
[FileName, FilePath] = uigetfile("*.xlsx;*.xls", "Select the right results file");
FullPath = fullfile(FilePath, FileName);
ImpOpts = detectImportOptions(FullPath);
ImpOpts.Sheet = 2;
ImpOpts.PreserveVariableNames = true;
MeasData = readtable(FullPath, ImpOpts);
The output contains only a part of the columns that I would need from Sheet 2 because it recognises as varibles the header from Sheet 1. I have never faced this issue before and feel like the solution must be stupid but I can't seem to find it.
I really need to use an integer to specify the sheet, but also by specifying the sheet name, it does not work. Has anyone had this problem before?
Thanks
Andrea

採用された回答

Stephen23
Stephen23 2023 年 11 月 29 日
編集済み: Stephen23 2023 年 11 月 29 日
ImpOpts = detectImportOptions(FullPath, "Sheet",2);
ImpOpts.PreserveVariableNames = true;
MeasData = readtable(FullPath, ImpOpts);
Or simply:
MeasData = readtable(FullPath, 'Sheet',2, 'VariableNamingRule','preserve')

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by