How to import data from multiple worksheets contained in 1 workbook?
1 回表示 (過去 30 日間)
古いコメントを表示
Purnjay Peshawaria
2020 年 6 月 21 日
編集済み: Purnjay Peshawaria
2020 年 6 月 22 日
Hi,
I have a workbook SelfStorageData.xls . It contains 3 worksheets . I want to import data from each of these 3 worksheets as 3 different matrices. Here is my code:
T = readtable('SelfStorageData.xls');
However, I get the following error:
Unable to open file 'SelfStorageData.xls' as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.
How can this be fixed? Excel Workbook attached.
0 件のコメント
採用された回答
Monalisa Pal
2020 年 6 月 22 日
編集済み: Monalisa Pal
2020 年 6 月 22 日
You may use the importdata function instead to fetch data in matrix but seeing that you have some non-numeric data, I wouldn't recommend it.
T = importdata('SelfStorageData.xlsx');
Then use variable names to access the individual matrices:
T1 = T.data.ExampleLeases;
T2 = T.data.TypicalMoveIn;
T3 = T.data.TypicalMoveOut;
Alternatively, you may look into https://www.mathworks.com/help/matlab/ref/matlab.io.spreadsheet.spreadsheetimportoptions.html
So, if you need to use the readtable function, you might do something like this. It's much more flexible.
T1 = readtable('SelfStorageData.xlsx', 'Sheet', 'Example Leases');
T2 = readtable('SelfStorageData.xlsx', 'Sheet', 'Typical Move In');
T3 = readtable('SelfStorageData.xlsx', 'Sheet', 'Typical Move out');
その他の回答 (1 件)
Walter Roberson
2020 年 6 月 22 日
Your file is SelfStorageData.xlsx but you try to read SelfStorageData.xls without the final 'x'
2 件のコメント
Monalisa Pal
2020 年 6 月 22 日
編集済み: Monalisa Pal
2020 年 6 月 22 日
Opps sorry, I missed the attachment. I just followed the comment. Thanks for pointing it out. I'll edit my answer.
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!