Read from Excel file as a plain table
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi everyone!
I have an excel file with the data like this:
The size (columns and rows quantity) is not defined and can be changed. Some data may be missing.
I want to get this table in Matlab as a simple table where every cell in the file is in a cell in the table. I do not need to use variable name read, to read in separate structures text and numerical data, or anything else. It will be more convenient to have only one variable as a table and then to get the required information and store it in a suitable variable format. For example, A4, A5, ... convert to datetime, to merge B1 and B2 into one string, numeric values as a matrix.
However, readtable() function always tries to do something with head, and I didn't find a way to skip it. The way like 'ReadVariableNames',false only do not read head, but I want to see it in the variable.
Could you please tell me what to do to import data from an excel file without such smart reading?
댓글 수: 2
dpb
2020년 11월 3일
The irregular nature of the arrangement in the spreadsheet is the primary culprit.
Why are there four (4) rows of data but only three (3) corresponding dates?
Creating the original file in a more consistent manner would simplify things a whole lot.
It will be simple enough to create the compound name from rows 1:2; what's not so clear is the remainder.
채택된 답변
dpb
2020년 11월 4일
편집: dpb
2020년 11월 4일
[~,~,r]=xlsread('yourfile.xls');
will return a cell array r that is a duplicate of the spreadsheet content with no interpretation of what is what if that is what is wanted.
Or, as Walter points out, the modern replacement would be readcell
댓글 수: 2
Peter Perkins
2020년 11월 18일
readcell would work, but then where are you? A big cell array that is probably not useful.
As other have said, this file is ... peculiar. If the first three lines are the same in all instances of these files, it would be easy to use readtable/readtimetable and tell it the number of header lines to skip, and to not read var names, and then add the desired var names by hand to the timetable you've read in. Or maybe read the first two lines of the file separately and build up the var names programmatically from that.
But there's the matter of four rows of measurements, and only three timestamps. That can't be right.
추가 답변 (1개)
drummer
2020년 11월 3일
Well, if you want to have this specific small table, then you could insert them in MATLAB manually.
Would it work?
If so, then you could use cell arrays and tell MATLAB the way you want the table, without the 'fancy' readtable features.
Again, bigger tables would not be ideal. But if you want this small one. I wonder that's ok.
This way, it will be ok to ignore the (relevant) observation from dpb.
Let us know if it worked for you.
Cheers
댓글 수: 2
drummer
2020년 11월 4일
편집: drummer
2020년 11월 4일
I have never dealt with such table formation.
I'm not familiar with your dataset but if you use Name and parameter as categorical variables and each date as a single variable (like hot-encoding your date variables) would not work?
So you would have
Name (categorial) | Parameter (categorical) | ParameterOutput (numerical) | Date 1 | Date 2 | Date 3
Unless you're not looking to fix your table layout. rs
I wonder dpb suggestion would work if that's the case.
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!